-
-
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
React-Router Location State being reset when changing queryState #839
Comments
Thanks for the report, we do forward the history.state when doing shallow updates so I guess this location state lives somewhere else in the router memory, I'll have to dive into the React Router codebase to track it down. Hopefully this is something that can be addressed without having to resort to a deep navigation (that calls the loaders). |
I managed to reproduce it, but only when using |
Sadly I can not confirm. In your Reproduction-setup have you also used it like in the root-component? import { BrowserRouter } from 'react-router-dom';
import { NuqsAdapter } from 'nuqs/adapters/react-router';
<NuqsAdapter>
<BrowserRouter>
<App />
</BrowserRouter>
</NuqsAdapter> On Tab Change i directly call the updateFunction of the const [tab, setTab] = useQueryState('tab', {
defaultValue: TabPanels.PICKING
});
const handleTabChange = useCallback(
(_event: React.SyntheticEvent, value: TabPanels) => {
setTab(value);
},
[setTab]
); But I can see this in my console.log: Have you also tested with ReactRouter: 6.22.3 ? Or any other idea what could be the issue? Thanks in advance. |
Could you try moving the adapter between BrowserRouter and the App components? I'm surprised the adapter even works if not placed under BrowserRouter. See #840. |
That actually fixes it. Although in the documentation under https://nuqs.47ng.com/docs/adapters#react-router-v6 it is specified to be the way I did it: export function ReactRouter() {
return (
<NuqsAdapter>
<RouterProvider router={router} />
</NuqsAdapter>
)
} |
Yeah that's what I just noticed when comparing with the e2e test environment. There are so many ways to setup React Router, I might have to try them all to update the docs. Regardless, the fix for shallow: false (which you only need if you have a loader that needs to read that search param) should be fairly easy. |
Could you please try the following (with
|
Yes I can verify. |
🎉 This issue has been resolved in version 2.3.1-beta.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This issue has been resolved in version 2.3.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Context
What's your version of
nuqs
?What framework are you using?
Which version of your framework are you using?
Description
When using the
state
property of location to forward some state and then using theuseQueryState
function, thelocation.state
is being reset tonull
.I also already tried all the possible options in the useQueryState-Options like
shallow: false
andhistory: "push"
The
location.state
should not be deleted by changing the querystate in my opinion.Reproduction
Component A:
Component B:
When Component A navigates to Component B, the location.state is an Object containing the previous location.
When the Nuqs-QueryState is being updated, the location.state is being set to
null
.The text was updated successfully, but these errors were encountered: