Skip to content

fix: Maintain location.state in React Router frameworks#840

Merged
franky47 merged 3 commits intonextfrom
fix/839-react-router-state
Jan 3, 2025
Merged

fix: Maintain location.state in React Router frameworks#840
franky47 merged 3 commits intonextfrom
fix/839-react-router-state

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.

@vercel
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

@pkg-pr-new
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
26 checks passed
@franky47 franky47 deleted the fix/839-react-router-state branch January 3, 2025 16:34
@github-actions
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 📦🚀

@github-actions
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