Skip to content

feat: add memory option in the testing adapter#1133

Merged
franky47 merged 6 commits intonextfrom
fix/1099-transient-previous-state-dev
Sep 17, 2025
Merged

feat: add memory option in the testing adapter#1133
franky47 merged 6 commits intonextfrom
fix/1099-transient-previous-state-dev

Conversation

@franky47
Copy link
Member

@franky47 franky47 commented Sep 12, 2025

Partial solution for the #1099 issue, where the state transients through an old value during testing.

This is not the most ideal solution as it may need a change in core, or in how the testing adapter resets its queue, but the lack of memory (state updates only using the initial search params as a base for updates) caused me a few headaches in tests, and this can help make the testing setup behave more closely to other adapters.

  • Add a note in the docs that this "memory" is per-adapter, and so is isolated between tests, but shared for components under the same adapter.

@franky47 franky47 added this to the 🪵 Backlog milestone Sep 12, 2025
@vercel
Copy link

vercel bot commented Sep 12, 2025

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

Project Deployment Preview Comments Updated (UTC)
nuqs Ready Ready Preview Comment Sep 17, 2025 8:50am

@pkg-pr-new
Copy link

pkg-pr-new bot commented Sep 12, 2025

pnpm add https://pkg.pr.new/nuqs@1133

commit: 1f3f96e

@franky47 franky47 changed the title fix: optimistic state resets to previous state in dev mode feat: add memory option in the testing adapter Sep 14, 2025
@franky47 franky47 marked this pull request as ready for review September 14, 2025 06:07
@franky47
Copy link
Member Author

franky47 commented Sep 14, 2025

@georgwittberger could you try the following deployment build in your setup please? I confirmed it passes the reset test in your reproduction repository.

pnpm add https://pkg.pr.new/nuqs@1133

You'll need to add the hasMemory: true prop on the <NuqsTestingAdapter>, or withNuqsTestingAdapter wrapper, to let the testing adapter record state updates internally, like other frameworks would.

Without memory, all state updates are based on the initial search params, which might work for testing units of behaviour, but causes problems with the optimistic state flow you described (brilliantly) in #1099 (comment).

There may be a better fix by seeing how to reset the queue differently in the testing adapter, I'll see if I can rework this PR later (but I think the memory mode has value on its own, for testing multiple updates in a more intuitive way).

@franky47 franky47 added the adapters/testing Uses the testing adapter for mocking URL behaviours in tests label Sep 14, 2025
@georgwittberger
Copy link

Yes, this works for the component test. Should solve the issues with the testing adapter.

@franky47 franky47 merged commit ccedc1b into next Sep 17, 2025
29 checks passed
@franky47 franky47 deleted the fix/1099-transient-previous-state-dev branch September 17, 2025 08:50
@github-actions
Copy link

🎉 This PR is included in version 2.7.0-beta.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions
Copy link

🎉 This PR is included in version 2.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@franky47 franky47 removed this from the 🚀 Shipping next milestone Sep 30, 2025
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 released on @beta released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants