-
-
Notifications
You must be signed in to change notification settings - Fork 135
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
useQueryState throttled option causes state to reset when component rerenders #726
Comments
Thanks, sorry it took so long to get into this issue. It looks like the Remix adapter needs to follow the same optimistic search params update we use in Next.js (and really all the other adapters should follow the same pattern). Let's assume we're typing "ab" in quick succession. The root of the issue was that, when the first request (for the first character typed, "a") is in flight, Remix's When the "?search=a" loader returns, the URL updates along with useSearchParams to The fix for this in Next was to use the I did some tests by following the same pattern and hacking together a Currently, the shallow option doesn't have an effect in Remix, everything was as if shallow was set to false, in contradiction with the docs. According to the Remix team, that is intentional: when the URL changes, loaders should re-run. In our case it's an issue as nuqs assumes local client-only updates by default, and only opts-in to server updates via Now as to why useQueryStates works: I think that's a double bug.. 😅 It looks like the sync mechanism fails at the right moment, skipping that temporary |
Hey, I published a couple of betas for nuqs 2.3.0, which includes better support for React Router-based frameworks (including Remix). Using Would you be able to give it a try in your project, and let me know if you hit any snags? I'm planning to release 2.3.0 in GA sometime next week. |
Note: [email protected] has been released with a fix for this issue. |
@franky47 thanks for all the write ups and debugging work. I kept following the updates during the holidays but had no time 😅 I just tried to update nuqs to validate if the issue is indeed resolved but I bumped into a different issue. nuqs 2.3.0 has a hard requirement on https://github.com/47ng/nuqs/blob/next/packages/nuqs/package.json#L132 Probably missing the |
Ah I see, I thought RRv7 used I'll update the version ranges to include 6 & 7 on both package names, would that work for you? |
Yeah I think that should work! |
Can you try with the following preview from #844 and see if it works better please?
|
@franky47 thanks! I can now install the new version and can also confirm that the |
Context
What's your version of
nuqs
?What framework are you using?
Which version of your framework are you using?
Description
Whenever the server finishes a request the component get's re-rendered and the useQueryState returns an old search state.
useQueryStates
does not have this issue, seems to only be happening withuseQueryState
If I read the docs I would assume this should not be the case https://nuqs.47ng.com/docs/options#throttling-url-updates
the state returned by the hook is always updated instantly, to keep UI responsive. Only changes to the URL, and server requests when using shallow: false, are throttled.
Reproduction
https://stackblitz.com/~/github.com/gijsroge/nuqs-throttle-issue?file=app/routes/_index.tsx
If you type in the search box you will notice the issue.
This issue is only apparent if you use the throttle feature.
The text was updated successfully, but these errors were encountered: