-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[v6][Bug]: navigate() with non-serializable state should throw error #8665
Comments
Seconding this. I tried to add a function as a member of the state object. While it's quite clear from the documents that "Location state values will get serialized, so something like new Date() will be turned into a string," this seems like something that the library should warn about and reject. The actual behavior—the router reloads the URL from the upstream server—sent me on a wild goose chase for a bug in my routing logic. |
+1 on this. Took me a lot to debug why my page gets reloaded when I pass the state to Link component (in my case I was passing down moment object, had to transform it to a string). |
I think I have the same problem with the Link component, with which I try to pass a component in the state. it tooks me 3 hours to understand where the bug originate |
Also think a development only error message or warning would be great, since it requires a bit of digging to find that you cant pass non-serializable state into navigate. |
IMO, a correct documentation should also link to the specification of what is "serializable". Mainly, Functions and Symbols cannot be serialized. |
Looks like we can detect this and re-throw via https://html.spec.whatwg.org/multipage/nav-history-apis.html#shared-history-push/replace-state-steps |
This is fixed by #10427 and will be available once the next release goes out (likely |
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
What version of React Router are you using?
6.2.1
Steps to Reproduce
Pass non serializable state to navigate()
Code for reproduction
https://codesandbox.io/s/react-router-navigate-bug-d9mlsn
Expected Behavior
Fail with some error since state must be serializable.
Actual Behavior
It changes browser's location instead of manipulating react-router's state without error. which makes devloper harder to find about their mistake because of wierd behavior.
The text was updated successfully, but these errors were encountered: