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: Use optimistic search params in app router #718

Merged
merged 5 commits into from
Oct 29, 2024
Merged

Conversation

franky47
Copy link
Member

@franky47 franky47 commented Oct 28, 2024

When using a combination of shallow: false, startTransition (from useTransition), and slow RSC computation, there can be a race condition where sending two or more updates before the first RSC response arrives, the useSearchParams update with the intermediate value and cause optimistic URL & UI updates (internal state) to sync to incorrect values. When the last RSC payload finished streaming in, the whole UI became eventually consistent, but this caused flickering issues.

Fixing this by feeding the nuqs hooks an optimistic version of useSearchParams in the app router adapter, and triggering this optimistic update when updating the URL (where we already do this kind of optimistic update with a shallow update before calling the router).

See #714.

Copy link

vercel bot commented Oct 28, 2024

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 Oct 29, 2024 0:03am

Copy link

pkg-pr-new bot commented Oct 28, 2024

Open in Stackblitz

pnpm add https://pkg.pr.new/nuqs@718

commit: 9b07e04

@franky47 franky47 marked this pull request as ready for review October 29, 2024 12:19
@franky47 franky47 changed the title fix: Try and handle RSC race conditions fix: Use optimistic search params in app router Oct 29, 2024
@franky47 franky47 merged commit b5c0168 into next Oct 29, 2024
23 checks passed
@franky47 franky47 deleted the fix/714-sync branch October 29, 2024 12:27
@franky47
Copy link
Member Author

🎉 This PR is included in version 2.1.0 🎉

The release is available on:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant