test(replays): Read live location in nuqs test adapter#116803
Merged
Conversation
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>
nsdeschenes
approved these changes
Jun 3, 2026
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.
The nuqs testing adapter (
tests/js/sentry-test/nuqsTestingAdapter.tsx) capturedlocationfromuseLocation()inside itsupdateUrlandgetSearchParamsSnapshotclosures. Because nuqs flushes updates on a deferred tick (always at leastsetTimeout(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
useFiltersInLocationQuerymigration to nuqsuseQueryStates(#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.specthen failed because callingsetSearchTermafter a project filter droppedf_e_project.This reads
locationthrough a ref that's updated every render, so the deferred flush composes onto the live URL — matching the real react-router v6 adapter, which readswindow.location/historyfresh 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.locationdirectly like production, but Sentry's TestRouter is in-memory, so a latest-ref overuseLocationis the correct source.