Closed firatciftci closed 1 month ago
Ah I thought this could come back up when I was refactoring for v2, but the test that covered it before passed.
I believe the issue was that we need to take the value from the update queue into account when reading the initial search params for the internal state. There was an issue for this, let me dig around and I'll come back to you.
Edit: yes it was #359. So maybe the test isn't going far enough.
Could you try this and let me know if it fixes your problem please?
pnpm add https://pkg.pr.new/nuqs@703
Seems to be fixed! Thank you so much once again for your super swift response.
Cool, I'll find a way to properly test this to prevent regressions and I'll publish a release tomorrow.
:tada: This issue has been resolved in version 2.0.4 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
Context
What's your version of
nuqs
?What framework are you using?
Which version of your framework are you using?
Description
After upgrading to
nuqs@2.0.3
(fromnuqs@1.20.0
), a regression appeared where changing a query parameter fromnull
to any value does not trigger an update to the value stored inuseQueryState(s)
if the component that calls the hook is rendered conditionally. The hook returnsnull
on initial change of the query parameter fromnull
to a value, and starts behaving as expected only after subsequent changes to the query parameter.Reproduction
Custom query parameter hook:
The main component:
The child component:
There exists a separate component with a list of cards in which pressing on a card changes the
itemId
value to a specific string:When no value is selected, pressing on the first button changes the URL appropriately, but
<ChildComponent />
does not register thatitemId
is set to"value1"
; it continues to returnnull
. However, whileitemId
is"value1"
, a subsequent click on the second button changes the URL appropriately once again, and now<ChildComponent />
is able to register the query value as"value2"
.Removing the conditional render of
<ChildComponent />
makes the issue go away. This bug does not appear in the version ofnuqs
prior to version 2.