Skip to content
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

Race-condition when pressing **Back** while the page is still loading when not using SSR #12924

Open
aloisklink opened this issue Oct 31, 2024 · 2 comments · May be fixed by #12925
Open

Race-condition when pressing **Back** while the page is still loading when not using SSR #12924

aloisklink opened this issue Oct 31, 2024 · 2 comments · May be fixed by #12925
Labels
bug Something isn't working

Comments

@aloisklink
Copy link
Contributor

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:

const is_hash_change = strip_hash(location) === strip_hash(current.url);
, and seems to be have been introduced in aabe33c

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:
[email protected]
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.

@aloisklink aloisklink linked a pull request Oct 31, 2024 that will close this issue
6 tasks
@eltigerchino
Copy link
Member

eltigerchino commented Nov 11, 2024

I can't seem to reproduce the issue. After refreshing the page, the setTimeout prevents the page from loading immediately, and if I click the back button, it shows the Home page without any errors.

@aloisklink
Copy link
Contributor Author

I can't seem to reproduce the issue. After refreshing the page, the setTimeout prevents the page from loading immediately, and if I click the back button, it shows the Home page without any errors.

Ah, that's my fault (it's my first time using Stackblitz)! For some reason, the Stackblitz had export const ssr = true;, and this bug only happens when SSR is disabled (maybe I was testing this previously, and I accidentally saved it).

Please try again (and if you still see export const ssr = true;, try disabling it)!

@eltigerchino eltigerchino added bug Something isn't working and removed awaiting submitter labels Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants