Description
Describe the bug
When loading a non-SSR page and pressing the browser's back button while the page is still loading, it's possible for current.url
to still be the default value of null
, which then causes the popState
function to throw the following uncaught error:
Uncaught (in promise) TypeError: Cannot destructure property 'href' of 'object null' as it is null.
at strip_hash (url.js?v=3a24e001:84:30)
at client.js?v=3a24e001:2227:52
The error is from current.url
being null
in:
kit/packages/kit/src/runtime/client/client.js
Line 2234 in e41a8e2
I've got a PR pending for this, but I'm not 100% on my fix, so I thought I'd make an issue just to be sure!
Reproduction
https://stackblitz.com/edit/sveltejs-kit-template-default-51wzhl?file=README.md
If I go to the /about
page, which has contents:
export const prerender = false;
export const ssr = false;
export async function load() {
await new Promise((resolve) => setTimeout(() => resolve(), 10_000));
return { text: 'hello world' };
}
If I then refresh the page, then press the Back button on my mouse before it's finished loading the PageData, nothing happens (other than seeing the error in the console):
Screencast.from.2024-10-31.20-45-32.webm
Logs
Uncaught (in promise) TypeError: Cannot destructure property 'href' of 'object null' as it is null.
at strip_hash (url.js?v=718158da:84:30)
at client.js?v=718158da:2227:52
System Info
~/projects/sveltejs-kit-template-default-51wzhl 59s
❯ npx envinfo --system --binaries --browsers --npmPackages "{svelte,@sveltejs/*,vite}"
Need to install the following packages:
envinfo@7.14.0
Ok to proceed? (y) y
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: 18.20.3 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.2.3 - /usr/local/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
@sveltejs/adapter-auto: ^3.0.0 => 3.3.1
@sveltejs/kit: ^2.0.0 => 2.7.3
@sveltejs/vite-plugin-svelte: ^4.0.0 => 4.0.0
svelte: ^5.0.0 => 5.1.4
vite: ^5.0.3 => 5.4.10
Severity
annoyance
Additional Information
This is pretty minor, but I've got @getsentry setup on a SvelteKit site, and I'm noticing that it's happening quite a bit.