Skip to content

bug: Prevent compare swap from refetching user data #189

Description

@O2sa

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.tsx correctly uses type="button" for the swap action, so this is not a form-submit issue.
  • components/home-page-client.tsx swaps username1/username2, calls router.push(...), and then swaps data.user1/data.user2 locally.
  • The useEffect that watches searchParams runs after the router.push and calls syncToUrl(...).
  • syncToUrl(...) builds a new fetch key with the reversed username order, so it does not match lastFetchedKeyRef.current and calls handleCompare(..., { 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 syncToUrl does 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/compare again.

Tip

🚀 Want to contribute?
Comment assign me to be automatically assigned to this issue via our GitHub Actions bot. Happy coding! ✨

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions