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: Maintain location.state in React Router frameworks #840

Merged
merged 3 commits into from
Jan 3, 2025

Conversation

franky47
Copy link
Member

@franky47 franky47 commented Jan 2, 2025

When using shallow: false, any user state set using navigate('url', { state: whatever }) was reset to null.

Kind of a hack to read it from history.state.usr, but it seems to work without adding a useLocation dependency (which might cause loss of referential stability for the state updater function and possibly extra renders). However, this will limit it to the BrowserRouter, and not be compatible with the in-memory router (which wasn't compatible before anyway, and is unlikely to ever be).

Closes #839.

Copy link

vercel bot commented Jan 2, 2025

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 Jan 3, 2025 4:34pm

Copy link

pkg-pr-new bot commented Jan 2, 2025

Open in Stackblitz

npm i https://pkg.pr.new/nuqs@840

commit: a3da934

@franky47 franky47 marked this pull request as ready for review January 2, 2025 16:52
@franky47 franky47 enabled auto-merge (squash) January 3, 2025 16:32
@franky47 franky47 merged commit 39d6f4a into next Jan 3, 2025
27 checks passed
@franky47 franky47 deleted the fix/839-react-router-state branch January 3, 2025 16:34
Copy link

github-actions bot commented Jan 4, 2025

🎉 This PR is included in version 2.3.1-beta.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Copy link

🎉 This PR is included in version 2.3.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@franky47 franky47 mentioned this pull request Jan 14, 2025
@franky47 franky47 removed this from the 🚀 Shipping next milestone Jan 14, 2025
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.

React-Router Location State being reset when changing queryState
1 participant