Skip to content

test(replays): Read live location in nuqs test adapter#116803

Merged
NicoHinderling merged 1 commit into
masterfrom
fix/nuqs-test-adapter-live-location
Jun 3, 2026
Merged

test(replays): Read live location in nuqs test adapter#116803
NicoHinderling merged 1 commit into
masterfrom
fix/nuqs-test-adapter-live-location

Conversation

@NicoHinderling
Copy link
Copy Markdown
Contributor

The nuqs testing adapter (tests/js/sentry-test/nuqsTestingAdapter.tsx) captured location from useLocation() inside its updateUrl and getSearchParamsSnapshot closures. Because nuqs flushes updates on a deferred tick (always at least setTimeout(0)), two setter calls fired back-to-back composed onto a stale render snapshot — so the second update dropped query params set by the first.

This surfaced after the useFiltersInLocationQuery migration to nuqs useQueryStates (#116768). The old code merged manually ({...query, ...updatedQuery}) and always preserved prior params; the new code delegates preservation to nuqs reading the live URL. useErrorFilters.spec then failed because calling setSearchTerm after a project filter dropped f_e_project.

This reads location through a ref that's updated every render, so the deferred flush composes onto the live URL — matching the real react-router v6 adapter, which reads window.location/history fresh at flush time. It's a test-harness correction: production was never affected, since the production adapter already reads live location and composes sequential setters correctly.

Considered making the adapter read window.location directly like production, but Sentry's TestRouter is in-memory, so a latest-ref over useLocation is the correct source.

The nuqs testing adapter captured location from useLocation() in its
updateUrl and getSearchParamsSnapshot closures. Because nuqs flushes
updates on a deferred tick, back-to-back setter calls composed onto a
stale render snapshot and dropped previously-set query params, failing
useErrorFilters.spec after the useFiltersInLocationQuery nuqs migration.

Read location through a ref that updates each render so deferred flushes
compose onto the live URL, matching the real react-router adapter which
reads window.location/history at flush time. This is a test-harness
correction; production was never affected.

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Jun 3, 2026
@NicoHinderling NicoHinderling marked this pull request as ready for review June 3, 2026 19:32
@NicoHinderling NicoHinderling requested a review from a team as a code owner June 3, 2026 19:32
@NicoHinderling NicoHinderling added the Trigger: Override Selective Testing Run the full test suite; necessary in cases where selected tests are flaky due to reshuffling label Jun 3, 2026
@NicoHinderling NicoHinderling enabled auto-merge (squash) June 3, 2026 19:38
@NicoHinderling NicoHinderling merged commit cd88768 into master Jun 3, 2026
90 checks passed
@NicoHinderling NicoHinderling deleted the fix/nuqs-test-adapter-live-location branch June 3, 2026 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components Trigger: Override Selective Testing Run the full test suite; necessary in cases where selected tests are flaky due to reshuffling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants