-
-
Notifications
You must be signed in to change notification settings - Fork 220
perf: bail out of state updates for equal values #1160
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
Conversation
|
@TkDodo is attempting to deploy a commit to the 47ng Team on Vercel. A member of the Team first needs to authorize it. |
commit: |
|
Could this be a solution to #924 (comment) ? |
Hm, I don't think so. The bailout happens later, only for setting component state. And with clearOnDefault: false, we might actually need to write to the url even though we set to the same value in state if it's equal to the default. |
|
@franky47 do you know what I can do against the react-router v7 test failure? I think this is a shared test, but it seems that we have one fewer re-renders now (which is a good thing) |
|
I'll run it again, the render test can be flaky sometimes, I don't like it but it has been useful in detecting major re-render changes in the past. |
|
I also need to add another test that calls |
|
The one change I see that could happen here is that a |
|
I actually messed up the last refactoring and the test showed it 🎉 Should be good now: f17fe59 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
I think there was a place in the docs or the playground (need to dig) where I explored a pattern to collect state changes locally, without updating the URL (to avoid polluting the global history), and submit all in one go by using this To be fair, the |
|
hmm I 'm not seeing that anywhere 🤔 |
|
Found it, it's the deferred test in the e2e-next environment (which could be a shared one), and it still passes apparently: |
|
🎉 This PR is included in version 2.7.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Co-authored-by: François Best <[email protected]>
When
useQueryStatesreceives an event that should update its internal state. we should bail out of that update if we already store the same value.This is what React’s
useStatedoes per default (by comparing withObject.is), however, it doesn’t work to delegate this to React because the internal state ofuseQueryStatesis an object. When an event comes in, we only update a single value of that object:so we can optimize ourselves by comparing the current state for that key with the new state that comes in from the emit and skip calling
setInternalStatefor those cases.This perf fix will be helpful for the
writeDefaultsfeature:because writing the default value to the url upon rendering should not trigger another render, as the states are already equal.