Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Referential stability for the state updater function #841

Merged
merged 2 commits into from
Jan 3, 2025

Conversation

franky47
Copy link
Member

@franky47 franky47 commented Jan 3, 2025

Passing the whole adapter in the useCallback dependency array caused it to be regenerated every time the search params changed.

By extracting only the properties we're interested in, we can ensure proper stability.

useQueryStates requires another layer: passing the keyMap as-is is usually not stable, as it's often defined inline in the calling component (and not something we want to change).

We can get away with adding only the keys to the dependency array, as changing the parser type for a given key is not supported (due to the sync layer, it can cause undesired behaviours and de-sync between types and runtime).

Copy link

vercel bot commented Jan 3, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nuqs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 3, 2025 3:24am

@franky47 franky47 added this to the 🪵 Backlog milestone Jan 3, 2025
Copy link

pkg-pr-new bot commented Jan 3, 2025

Open in Stackblitz

npm i https://pkg.pr.new/nuqs@841

commit: 3973990

@franky47 franky47 marked this pull request as ready for review January 3, 2025 03:39
@franky47 franky47 merged commit c089be2 into next Jan 3, 2025
27 checks passed
@franky47 franky47 deleted the fix/referential-stability branch January 3, 2025 08:54
Copy link

github-actions bot commented Jan 4, 2025

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

The release is available on:

Your semantic-release bot 📦🚀

Copy link

🎉 This PR is included in version 2.3.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@franky47 franky47 mentioned this pull request Jan 14, 2025
@franky47 franky47 removed this from the 🚀 Shipping next milestone Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

update a.k.a setter function is not stable in v2
1 participant