Skip to content

fix: reset the testing adapter's URL update queue once per mount - #1518

Draft
inf1nite-lo0p wants to merge 2 commits into
47ng:nextfrom
inf1nite-lo0p:fix/testing-adapter-reset-queues-on-mount
Draft

fix: reset the testing adapter's URL update queue once per mount#1518
inf1nite-lo0p wants to merge 2 commits into
47ng:nextfrom
inf1nite-lo0p:fix/testing-adapter-reset-queues-on-mount

Conversation

@inf1nite-lo0p

Copy link
Copy Markdown

Fixes #1517.

NuqsTestingAdapter calls resetQueues() in the component body, guarded only by the resetUrlUpdateQueueOnMount prop, so despite the prop's name it runs on every render. With hasMemory, every flushed URL update re-renders the adapter (updateUrl calls setSearchParams). Combined, an update enqueued while that re-render is pending gets aborted by the adapter's own render: it never reaches the URL, and the abort's re-sync reverts every subscribed hook to the URL's stale value.

Following the contributing guide's suggestion, the first commit is the failing test and the second is the fix:

  1. test: a browser test that writes a value, then chains a second write on the first write's promise. The promise resolves at the end of the flush, so the second write is enqueued in a microtask before the adapter's pending re-render commits. On next this fails with onUrlUpdate called once instead of twice: the second write is aborted by the adapter's render body and the state reverts.
  2. fix: a ref guard so the reset runs once per mounted instance. The guard stays in the component body on purpose: moving it to an effect would run it after children's mount-time writes and abort those instead.

Verified locally: the new test fails on next without the fix and passes with it; pnpm --filter nuqs test:unit 262/262 and test:types pass; Prettier clean.

Where this was found, for context: a dashboard whose sheet stack lives in a ?sheets= param. A close dispatched right after an open's flush was silently dropped about 1 run in 15 locally and far more often on loaded CI runners, leaving the sheet permanently open in tests. Deterministic standalone reproduction with traces: https://github.com/inf1nite-lo0p/nuqs-1517-repro

@vercel

vercel Bot commented Aug 1, 2026

Copy link
Copy Markdown

@inf1nite-lo0p is attempting to deploy a commit to the 47ng Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: eb5734d4-1bc0-4df2-a22c-3eafcbbc6f30

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@vercel

vercel Bot commented Aug 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nuqs Ready Ready Preview Aug 2, 2026 8:22am

@franky47 franky47 added the adapters/testing Uses the testing adapter for mocking URL behaviours in tests label Aug 2, 2026
@franky47 franky47 added this to the 🪵 Backlog milestone Aug 2, 2026
@franky47 franky47 added the deploy:preview Deploy a preview version of this PR on pkg.pr.new label Aug 2, 2026
@pkg-pr-new

pkg-pr-new Bot commented Aug 2, 2026

Copy link
Copy Markdown
pnpm add https://pkg.pr.new/nuqs@1518

commit: 3912e84

@franky47 franky47 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for the implementation, the test works but could use a more robust implementation.

Feel free to try the pkg.pr.new preview build to see if it solves your initial use-case.


const waitForSettle = () =>
new Promise<void>(resolve => {
setTimeout(resolve, 100)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: Why 100ms here?

Comment on lines +16 to +17
let value: string | null = null
let setValue: (update: string | null) => Promise<unknown> = () =>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: I'd rather avoid closing on component internals, a more isolated way would be to render a test button to call the setter sequence and act on it.

@franky47 franky47 added the pr-waiting-for-feedback Waiting for issue reported to confirm fix from pkg.pr.new build. label Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adapters/testing Uses the testing adapter for mocking URL behaviours in tests deploy:preview Deploy a preview version of this PR on pkg.pr.new pr-waiting-for-feedback Waiting for issue reported to confirm fix from pkg.pr.new build.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NuqsTestingAdapter: resetUrlUpdateQueueOnMount runs on every render and (with hasMemory) aborts concurrently queued updates

2 participants