[bug] dynamic default values do not properly update
Author: dtaubCreated Oct 29, 2025Updated Oct 29, 2025
Labelsbug
Context
What's your version of nuqs?
2.7.2What framework are you using?
- ✅ Next.js (app router)
Which version of your framework are you using?
next 14.2.33
Description
There are 2 issues related to dynamic default values (changing the value passed to withDefault at runtime). From some trial and error, it looks like these both worked in nuqs 2.3.0 and are broken in 2.3.1.
- If the defaultValue changes at runtime, it partially updates but is out of sync. The new default value will clear the query param, but will set the value to the old default value.
It looks like this is fixed by adding defaultValues to the dependency array here
- If the default value (and by extension, the value) is an object, the default value never updates. This appears to be because the dependency array tries to check it as a string value, meaning no matter what, it sees an unchanging
[object Object]
Changing this line to .map(({ defaultValue }) => JSON.stringify(defaultValue)) seems to fix that
Reproduction
Example: Steps to reproduce the behavior:
- Go to https://codesandbox.io/p/devbox/g8gmlp
- Change the first input to "def"
- Type "def" into the second input
- The query param is cleared, but the input changes to "abc" (the default value in the code)
Source: 47ng/nuqs