kit icon indicating copy to clipboard operation
kit copied to clipboard

pushState causes error when called on component initialization or within onMount

Open Bohdan-Tereta opened this issue 2 years ago • 1 comments

Describe the bug

If we call pushState as part of component initialization, or within onMount, Sveltekit doesn’t have app.root initialized yet. What we can do as a workaround is add await tick() which will wait until pending DOM changes are complete.

image

Reproduction

call pushState() from $app/navigation in component directly or in onMount() method or in store subscription callback. Expected: no errors Actual: error in console and app broken, complaining app.root element could not be found (see screenshot in previous section). Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '$set')

Logs

No response

System Info

System:
    OS: macOS 14.3.1
    CPU: (16) arm64 Apple M3 Max
    Memory: 75.55 MB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.9.0 - ~/.nvm/versions/node/v20.9.0/bin/node
    npm: 10.5.2 - ~/Documents/Projects/sn-beyond-frontend/node_modules/.bin/npm
    pnpm: 8.15.6 - /opt/homebrew/bin/pnpm
  Browsers:
    Chrome: 124.0.6367.201
    Safari: 17.3.1
  npmPackages:
    @sveltejs/adapter-node: ^2.0.0 => 2.1.2 
    @sveltejs/adapter-static: ^3.0.0 => 3.0.1 
    @sveltejs/kit: ^2.5.7 => 2.5.0 
    @sveltejs/vite-plugin-svelte: ^3.1.0 => 3.1.0 
    svelte: ^4.2.15 => 4.2.15 
    vite: ^5.1.7 => 5.1.7

Severity

annoyance

Additional Information

No response

Bohdan-Tereta avatar May 10 '24 03:05 Bohdan-Tereta

Duplicate of #11466.

Conduitry avatar May 10 '24 09:05 Conduitry