-
Notifications
You must be signed in to change notification settings - Fork 11
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(atomWithHash): replaceState function to use window.history.state instead of null #24
Conversation
… instead of null My project uses the new NextJS app router, and we were using atomWithHash to keep track of state. This was breaking when used with the app router when using the back button in the browser. In my project I am just setting the setHash function to do what I committed here. I figured it would be better and easier for anyone else using this library to just set the flag replaceState if they are using the nextjs app router. (Maybe the website/documentation should be updated as well.)
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit fce6862:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good. I don't think we can add a test for it, right?
null, | ||
window.history.state, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch. I didn't realize this would be better.
ref: https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState
Please send PRs too! |
Not to my knowledge. |
|
Hi, I just realized that we should make the same change for atomWithLocation. |
My project uses the new NextJS app router, and we were using atomWithHash to keep track of state. This was breaking when used with the app router when using the back button in the browser. In my project I am just setting the setHash function to do what I committed here. I figured it would be better and easier for anyone else using this library to just set the flag replaceState if they are using the nextjs app router. (Maybe the website/documentation should be updated as well.)