Skip to content

fix(xtracter): sync popup source selection display with storage - #693

Merged
hmjn023 merged 1 commit into
developfrom
fix/xtracter-source-selection-sync
Aug 23, 2026
Merged

hmjn023 merged 1 commit into
developfrom
fix/xtracter-source-selection-sync

Conversation

@hmjn023

@hmjn023 hmjn023 commented Aug 23, 2026

Copy link
Copy Markdown
Owner

問題

xtracterのpopupでTarget Media Sourceを選択して閉じ、再度開くと表示が先頭のソースに戻っていた。ただし内部的には前回選択したidが chrome.storage.local に残っているため、単体upload(背景側の getTargetSourceId())は表示と違うソースへ保存されることがあった。

原因

  • popupが selectedSourceId を <select value> へ代入する時点でoptionsが未描画(空リスト)のため、ブラウザが存在しない値の代入を無視。その後 <For> がoptionsを描画してもvalueは再代入されず、表示は常に先頭へフォールバックしていた
  • 再取得(例: API URL入力)のたびにoptionノードが再生成され、選択表示が再び先頭へリセットされる経路もあった
  • findAll() に ORDER BY が無く「先頭」が非決定、backgroundは保存済みidの有効性を未検証

変更内容

  • apps/xtracter/src/popup/index.tsx: 保存idの先行セットをやめ、setSources() 後に解決したidをシグナルへ反映しつつ selectRef.value を明示再代入して表示を同期。リクエスト連番ガードで古いレスポンスを破棄。storage永続化はidが変わった場合のみ
  • apps/xtracter/src/utils/source-selection.ts: 解決ロジックを純関数 resolveEffectiveSourceId(sources, preferredId?, fallbackName?) に集約
  • apps/xtracter/src/background/index.ts: upload前に保存idを現在のソース一覧で検証し、削除済みなら "twitter" → 先頭へフォールバックして永続化。サーバ到達不能時は保存idをそのまま使用(挙動維持)
  • packages/db/src/repositories/source-repository.ts: findAll() に .orderBy(mediaSources.name) (一覧が名前順になる点に注意)
  • テスト基盤: apps/xtracter/vitest.config.ts 新設、解決ロジックの単体テスト追加、ルートのvitest projects/test scriptに組み込み(既存 twitter.test.ts も実行対象に)

検証

  • bun run check (biome + typecheck + design:lint) ✅
  • bun run --cwd apps/xtracter test (10 tests) および他パッケージのテスト ✅
  • bun run --cwd apps/xtracter build ✅
  • 実ブラウザでの確認(選択保持・単体uploadの保存先)は未実施のため、ロード後に要確認

The popup assigned select.value before options rendered, so the dropdown
always displayed the first source while storage kept the real selection;
single uploads resolved the source from storage and saved to a different
source than displayed. Resolve the effective source after options render,
re-apply the value via ref, guard against stale fetch responses, validate
the stored id in the background before uploads, order source lists by
name, and add vitest coverage for the resolution logic.
@coderabbitai

coderabbitai Bot commented Aug 23, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 1b21e8b3-76a6-448a-9672-b2e5f4d2cd49


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@hmjn023
hmjn023 merged commit 85fea52 into develop Aug 23, 2026
1 check passed
@hmjn023
hmjn023 deleted the fix/xtracter-source-selection-sync branch August 23, 2026 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant