Repository navigation
fix(xtracter): sync popup source selection display with storage - #693
Merged
Merged
Conversation
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.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 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. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
問題
xtracterのpopupでTarget Media Sourceを選択して閉じ、再度開くと表示が先頭のソースに戻っていた。ただし内部的には前回選択したidが
chrome.storage.localに残っているため、単体upload(背景側のgetTargetSourceId())は表示と違うソースへ保存されることがあった。原因
selectedSourceIdを<select value>へ代入する時点でoptionsが未描画(空リスト)のため、ブラウザが存在しない値の代入を無視。その後<For>がoptionsを描画してもvalueは再代入されず、表示は常に先頭へフォールバックしていた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✅