generated from chiffre-io/template-library
-
-
Notifications
You must be signed in to change notification settings - Fork 134
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: Ensure referential stability for values #617
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
franky47
changed the title
test: Making sure it fails beforehand
fix: Ensure referential equality for values
Aug 28, 2024
franky47
changed the title
fix: Ensure referential equality for values
fix: Ensure referential stability for values
Aug 28, 2024
franky47
force-pushed
the
fix/referential-stability
branch
from
August 30, 2024 19:16
ac6ab4a
to
82c10ae
Compare
So that internal refs can be synced together without calling the serializer on each reception site.
franky47
force-pushed
the
fix/referential-stability
branch
from
September 2, 2024 18:26
82c10ae
to
88d2c5e
Compare
commit: |
🎉 This PR is included in version 1.19.0-beta.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 1.19.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This was referenced Sep 2, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before this PR, any update of a search param (via nuqs or otherwise) would trigger all the parsers to run, causing unstable references for non-primitive states (objects, arrays, maybe even Dates?).
This caused effects to re-run needlessly, and it is wasteful: we already have the values, and other search params which haven't changed don't need to be parsed again.
This PR implements a cache of the serialized query string value along with the cache of the internal state (using React refs), and checks for a change before calling the parsers if needed.
Related tweet: https://x.com/fortysevenfx/status/1828786748354408489
Caveats
This is an edge case, but having two different parsers on the same key (eg:
parseAsInteger
andparseAsFloat
) will result in the latest updated value being propagated to all the hooks registered on the same key.Example: if setting
foo
to 1.234 via parseAsFloat, a hook listening tofoo
withparseAsInteger
will have a state of 1.234, not 1. Before this PR, the state would flash first with 1.234, then the parser would run and correct it to 1.Anyway, this is not a recommended use of the library (one key, one parser, then derive state if needed).