Skip to content

Conversation

@bartlangelaan
Copy link

@bartlangelaan bartlangelaan commented Oct 30, 2024

This utilizes the useSyncExternalStore hook in the React adapter, which automatically takes care of rehydration errors.

I'm unsure if it still works correctly, because this version does not use the emitter value anymore. It just gets it from the location every time. I will test it before marking it as ready.

@vercel
Copy link

vercel bot commented Oct 30, 2024

@bartlangelaan is attempting to deploy a commit to the 47ng Team on Vercel.

A member of the Team first needs to authorize it.

@bartlangelaan bartlangelaan marked this pull request as draft October 30, 2024 05:47
@franky47
Copy link
Member

Thanks, wow this is so much cleaner!

I had heard of useSyncExternalStore, but it didn't occur to me to use it here, it sounds like a perfect use-case. Great job!

@vercel
Copy link

vercel bot commented Oct 30, 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 30, 2024 10:57pm

@franky47 franky47 added the deploy:preview Deploy a preview version of this PR on pkg.pr.new label Oct 30, 2024
@bartlangelaan
Copy link
Author

I don't have time to test it today, so if you can't wait and want to test it, feel free! :-)

@franky47
Copy link
Member

Regarding the emitter, it's use is to make sure the searchParams returned by the adapter hook is reactive: when the URL changes, no matter the reason (internal query state change, Link, back/fwd navigation), every hook needs to get the new value.

@franky47 franky47 added deploy:preview Deploy a preview version of this PR on pkg.pr.new and removed deploy:preview Deploy a preview version of this PR on pkg.pr.new labels Oct 30, 2024
@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 30, 2024

Open in Stackblitz

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

commit: 6b2e0a2

@bartlangelaan bartlangelaan force-pushed the use-sync-external-store-react-adapter branch from 7a5fcba to 6b2e0a2 Compare October 30, 2024 21:14
@franky47 franky47 added the adapters/react Uses the React SPA adapter label Oct 30, 2024
@franky47
Copy link
Member

Hey, do you have some bandwidth to work on this again, or do you mind if I pick it up?

@bartlangelaan
Copy link
Author

I don't mind at all! I don't know when I will have time for this, so feel free!

@franky47 franky47 added this to the 🪵 Backlog milestone Nov 13, 2024
@franky47 franky47 requested a review from Copilot November 19, 2024 19:43
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 1 out of 1 changed files in this pull request and generated no suggestions.

Comments skipped due to low confidence (1)

packages/nuqs/src/adapters/react.ts:7

  • Changing the emitter type from { update: URLSearchParams } to { update: void } might cause issues if other parts of the codebase rely on the update event carrying a URLSearchParams payload.
const emitter = mitt<{ update: void }>()

@franky47
Copy link
Member

franky47 commented Oct 9, 2025

Closing this as we do use uSES for the optimistic state in core now, although we might migrate away from it to prefer useOptimistic when we start only supporting React ^19 (probably in nuqs@^3).

@franky47 franky47 closed this Oct 9, 2025
@franky47 franky47 added 🪦 graveyard Closed PRs (rejected, wontfix, temporary experiments) and removed 🪦 graveyard Closed PRs (rejected, wontfix, temporary experiments) labels Oct 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adapters/react Uses the React SPA adapter deploy:preview Deploy a preview version of this PR on pkg.pr.new

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants