Preserve history state on refresh when SSR is disabled
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
Description
Describe the bug
At this line svelte kit can pass state: history.state.
This would prevent history state loss when refreshing the page.
Current workaround:
Save the state in the root +layout.js and restore it the root +layout.svelte using history.replaceState(...data.savedState, null, location.href)
Reproduction
https://stackblitz.com/edit/sveltekit-preserve-history-state-bug?file=src/routes/+layout.js
Logs
No response
System Info
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 16.14.2 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 7.17.0 - /usr/local/bin/npm
npmPackages:
@sveltejs/adapter-auto: ^2.0.0 => 2.0.1
@sveltejs/kit: ^1.5.0 => 1.16.2
svelte: ^3.54.0 => 3.59.0
vite: ^4.3.0 => 4.3.5
Severity
annoyance
Additional Information
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at packages/kit/src/runtime/client/start.js around the linked line and reproduce the behavior with the linked StackBlitz example, focusing on refreshes when SSR is disabled. Compare the current history state handling with the requested behavior, then verify that the reproduction preserves history state after refresh without relying on the root +layout.js and +layout.svelte workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100