bug: Prevent compare swap from refetching user data #189
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't workingcomparisongood first issueGood for newcomersGood for newcomersperformanceui
Description
Clicking the swap button on the compare page should only swap the two already-loaded users in the UI and update the URL order. Currently it can trigger a fresh /api/compare request after the URL changes, even though the same two users are already available locally.
Context
components/compare-form.tsxcorrectly usestype="button"for the swap action, so this is not a form-submit issue.components/home-page-client.tsxswapsusername1/username2, callsrouter.push(...), and then swapsdata.user1/data.user2locally.- The
useEffectthat watchessearchParamsruns after therouter.pushand callssyncToUrl(...). syncToUrl(...)builds a new fetch key with the reversed username order, so it does not matchlastFetchedKeyRef.currentand callshandleCompare(..., { updateUrl: false }), causing an unnecessary refetch.
Tasks
- Make compare fetch deduplication treat swapped username pairs as the same comparison when selected languages are unchanged, or track a swap-only URL update so
syncToUrldoes not refetch. - Ensure
swapUsers()preserves selected language query params when updating the URL. - Keep the local data swap behavior so the UI updates immediately without loading state.
- Add a regression test or interaction test that verifies clicking swap does not call
/api/compareagain.
Tip
🚀 Want to contribute?
Comment assign me to be automatically assigned to this issue via our GitHub Actions bot. Happy coding! ✨
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingcomparisongood first issueGood for newcomersGood for newcomersperformanceui
Activity