History state is overwritten to `{}` during navigation since `next.208`
See original GitHub issueDescribe the bug
Since @sveltejs/kit@1.0.0-next.208
, goto()
's state
parameter stopped working. This line is overwriting the state to {}
whenever navigation occurs:
This is the commit that introduced the bug: https://github.com/sveltejs/kit/commit/d17f459ef35f07f012d77ff7c8665e26380448cd.
Reproduction
- Open the repro: https://stackblitz.com/edit/sveltekit-xfxpb3
- Click the button “Goto with state”.
- It will take you to another route where the History state will be visible.
- You’ll see the state will be empty. It should be what was passed to
goto()
.
Logs
No response
System Info
System:
OS: macOS 12.0.1
CPU: (8) arm64 Apple M1
Memory: 112.81 MB / 8.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.13.1 - ~/.asdf/installs/nodejs/16.13.1/bin/node
Yarn: 1.22.17 - ~/.asdf/installs/nodejs/16.13.1/.npm/bin/yarn
npm: 8.2.0 - ~/.asdf/installs/nodejs/16.13.1/.npm/bin/npm
Watchman: 2021.11.15.00 - /opt/homebrew/bin/watchman
Browsers:
Chrome: 97.0.4692.71
Safari: 15.1
npmPackages:
@sveltejs/adapter-auto: 1.0.0-next.9 => 1.0.0-next.9
@sveltejs/kit: 1.0.0-next.208 => 1.0.0-next.208
svelte: 3.44.3 => 3.44.3
Severity
blocking all usage of SvelteKit
Additional Information
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to replace the location hash and only keep the last ...
Then, set the location.hash property. If we went back in the history in the previous step, the history entry is overwritten. The fallback...
Read more >AVEVA™ - Application Server - formerly Wonderware
Sending Historical Data Between Application Server and the Historian . ... Aggregated Alarm Display in AVEVA OMI Navigation .
Read more >Visualforce in Practice - Salesforce Developers
1-2 shows the associated view state which contains an account instance since it has been declared as a non transient member variable in...
Read more >IO tools (text, CSV, HDF5, …) — pandas 1.5.2 documentation
Passing in False will cause data to be overwritten if there are duplicate names in the columns. Deprecated since version 1.5.0: The argument...
Read more >JAN-7201/9201
Playing Back Data Recorded During. Navigation [Playback]. 18. Maintenance & Inspection. 19. Failures and After-Sale Services. 20. About Disposal.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@benmccann Local storage, session storage, and history state are not interchangeable. They have different lifecycles and serve different needs.
Whenever you have data that only makes sense for a specific route, history state is the way to go.
Actual use case: history-controlled modals
I have
historyState
which is a store that listens tohistory.state
. To open the modal, I add a history entry with its state determining that the modal should be open. If the user presses the back button, the modal will automatically close. It’s as simple as it can get. Using local storage or session storage would require me to basically keep them in sync with the history.That said, I think there would be no problem if I had to call
history.pushState
directly instead of usinggoto
. 🤔I’m closing since it was fixed in https://github.com/sveltejs/kit/commit/e3cb69b716b7e1c71580c665a606b906fb670b2c.