Skip to content

Svelte 5.27.1 - Cannot access <snippet> before initialization on page refresh #15786

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

Closed
catalin-l opened this issue Apr 17, 2025 · 0 comments · Fixed by #15789
Closed

Svelte 5.27.1 - Cannot access <snippet> before initialization on page refresh #15786

catalin-l opened this issue Apr 17, 2025 · 0 comments · Fixed by #15789
Assignees

Comments

@catalin-l
Copy link

catalin-l commented Apr 17, 2025

Describe the bug

I've been using Svelte for the past few months, so I'm not sure if this is caused by bad practice, or an actual issue. It was not present in 5.27.0, so it looks like an issue.

I'm basically using context to store Snippets so I can hot swap parts of the layout based on the page. This worked fine until today when I updated from 5.27.0 to 5.27.1.

It looks to be working fine if the content is static (just regular HTML, text) , but it breaks once a $state variable is used in the Snippet.

Reproduction

  1. Load app
  2. Click "Test" anchor
  3. Refresh page

Repo: https://github.com/catalin-l/svelte-slot-test

Logs

ReferenceError: Cannot access 'sidebar' before initialization
    at _page (/home/catalin/Development/bugs/svelte-slot-test-main/src/routes/test/+page.svelte:4:13)
    at eval (/home/catalin/Development/bugs/svelte-slot-test-main/.svelte-kit/generated/root.svelte:66:5)
    at _layout (/home/catalin/Development/bugs/svelte-slot-test-main/src/routes/+layout.svelte:14:11)
    at Root (/home/catalin/Development/bugs/svelte-slot-test-main/.svelte-kit/generated/root.svelte:61:3)
    at render (/home/catalin/Development/bugs/svelte-slot-test-main/node_modules/.pnpm/[email protected]/node_modules/svelte/src/internal/server/index.js:88:2)
    at Function._render [as render] (/home/catalin/Development/bugs/svelte-slot-test-main/node_modules/.pnpm/[email protected]/node_modules/svelte/src/legacy/legacy-server.js:27:24)
    at render_response (/home/catalin/Development/bugs/svelte-slot-test-main/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected]_l_uydtfn24dfo5ird66jvbjiwfrm/node_modules/@sveltejs/kit/src/runtime/server/page/render.js:192:29)
    at async render_page (/home/catalin/Development/bugs/svelte-slot-test-main/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected]_l_uydtfn24dfo5ird66jvbjiwfrm/node_modules/@sveltejs/kit/src/runtime/server/page/index.js:299:10)
    at async resolve (/home/catalin/Development/bugs/svelte-slot-test-main/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected]_l_uydtfn24dfo5ird66jvbjiwfrm/node_modules/@sveltejs/kit/src/runtime/server/respond.js:499:18)
    at async respond (/home/catalin/Development/bugs/svelte-slot-test-main/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected]_l_uydtfn24dfo5ird66jvbjiwfrm/node_modules/@sveltejs/kit/src/runtime/server/respond.js:363:20)

System Info

System:
  OS: Linux 6.14 Fedora Linux 42 (Workstation Edition)
  CPU: (16) x64 AMD Ryzen 7 7745HX with Radeon Graphics
  Memory: 4.46 GB / 14.80 GB
  Container: Yes
  Shell: 5.2.37 - /bin/bash
Binaries:
  Node: 22.12.0 - ~/.volta/tools/image/node/22.12.0/bin/node
  npm: 10.9.0 - ~/.volta/tools/image/node/22.12.0/bin/npm
  pnpm: 9.15.0 - ~/.volta/bin/pnpm
Browsers:
  Brave Browser: 135.1.77.97
npmPackages:
  svelte: ^5.27.1 => 5.27.1 

This also has been tested on my work Macbook Pro M4 and the behaviour is the same.

Severity

blocking an upgrade

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants