-
-
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
Nuqs rerender count in NextJS #822
Comments
Updating the URL is an asynchronous operation, and nuqs does optimistic state updates to keep the UI responsive, so having more renders than with a simple synchronous, local useState, is expected. 8 times feels a little high though. Your reproduction repo is just a stock create-next-app, did you forget to push a commit? See also: #516. |
@franky47 Sorry for the confusion earlier. I've updated the repo; could you please take a look? Just to clarify, the comparison here is not with Can you check the console logs during the tests to help track this? When we set My primary use case here is a data table where I’d prefer not to update optimistically, since the data is coming from the server. My goal is to minimize these costly re-renders. Let me know what you think, and thanks for your help! |
Hey, I managed to take a look at your repro, and I can only see 4 renders (the doubles you see are due to StrictMode). You can see only four when building for production. There might be something I can do to reduce it to 3, see #755 (comment). |
@alberto-htl I did some render counts in #849, and fixed a couple of issues that could have caused extra renders. It should be more stable at 2 renders on shallow: true and 3 renders on shallow: false in the app router. Feel free to try |
@franky47 That's great! I will take a look. Thank you for your support |
Context
What's your version of
nuqs
?What framework are you using?
Which version of your framework are you using?
Description
The component is rerender 8 times while the component with the default hooks of nextjs is rerendered only 2 times.
Expected behavior is to both component rerender the same amount of times.
The demo offer two components one using the nextjs hooks directly, and another using useQueryState from nuqs.
To test it, use the button. Test the nextjs component and check the console logs. Then use the button on the component that use nuqs and check the console logs.
Reproduction
https://github.com/dev2xl/nuqs-rerender-demo
The text was updated successfully, but these errors were encountered: