-
-
Notifications
You must be signed in to change notification settings - Fork 199
Description
Context
What's your version of nuqs
?
2.5.1
What framework are you using?
- ✅ Next.js (app router)
- ❌ Next.js (pages router)
- ❌ React SPA (no router)
- ❌ Remix
- ❌ React Router
- ❌ Other (please specify)
Which version of your framework are you using?
15.5.2
Description
When using the NuqsTestingAdapter
component in unit tests (Vitest, JSDOM) the setter functions returned by useQueryState
are not memoized. The function changes on every render causing effects that depend on it to rerun more often than expected.
Reproduction
https://github.com/georgwittberger/nuqs-errors-repro
https://stackblitz.com/github/georgwittberger/nuqs-errors-repro
- Install dependencies, then run unit tests:
npm run test
- See the failing tests in
src/app/setters/page.test.tsx
. These tests are expected to succeed.
The component renders a text indicating whether the setter function was exactly the same as in the previous render. In these unit tests the function identity changes.
However, in the browser with NuqsAdapter
from nuqs/adapters/next/app
this problem does not occur. The setter function is always the same there when the state changes.