Repository: sveltejs/kit

Issue #12924: Race-condition when pressing **Back** while the page is still loading when not using SSR
Created: 2024-10-31T11:53:47Z
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
    
  
  
    

        
          
           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:
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.

Duplicate issue #13145: Cannot destructure property 'href' of 'object null' as it is null.
Created: 2024-12-11T12:06:15Z
Describe the bug
This was logged in our Sentry:

Reproduction
Not sure how this is reproduced. If you have an idea on where this happens then i can try to make a minimal repro.
Logs
No response
System Info
System:
    OS: macOS 15.1.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 130.55 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.0 - ~/.nvm/versions/node/v20.11.0/bin/node
    npm: 10.2.4 - ~/.nvm/versions/node/v20.11.0/bin/npm
    pnpm: 9.13.2 - /opt/homebrew/bin/pnpm
    bun: 1.0.0 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 131.1.73.91
    Chrome: 131.0.6778.139
    Edge: 131.0.2903.86
    Safari: 18.1.1
  npmPackages:
    @sveltejs/adapter-vercel: ^5.5.2 => 5.5.2 
    @sveltejs/enhanced-img: ^0.4.3 => 0.4.3 
    @sveltejs/kit: ^2.10.1 => 2.10.1 
    @sveltejs/vite-plugin-svelte: ^5.0.1 => 5.0.1 
    svelte: ^5.10.1 => 5.10.1 
    vite: ^6.0.3 => 6.0.3
Severity
annoyance
Additional Information
No response

Closing comment (2025-01-17T09:22:40Z): I'm 95% sure this is a duplicate of #12924 and should be fixed by #12925! (your @getsentry error looks very similar to the one that I had!).
To be sure, try upgrading to @sveltejs/kit@2.15.3 and see if that stops this Sentry event from happening again!