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

Svelte 5: Bug - ReferenceError occurs when defining a snippet inside a script along with bind:value in SSR mode. #11086

Closed
mariansimecek opened this issue Apr 7, 2024 · 2 comments · Fixed by #11104
Assignees
Milestone

Comments

@mariansimecek
Copy link

Describe the bug

Can't define a snippet and bind a value at the same time. This leads to the error: ReferenceError: snippet is not defined. This only happens in SvelteKit with SSR mode on, when I disable it, everything works fine.

<!-- +page.svelte -->
<script>
	import TextInput from './TextInput.svelte';

	let value = $state('');
	const _snippet = snippet;
</script>

{#snippet snippet()}
	Something
{/snippet}

<TextInput bind:value />
value: {value}
<!-- TextInput.svelte -->
<script>
	let { value = $bindable() } = $props();
</script>

<input type="text" bind:value />

Probably related to #11010

Reproduction

repo:
https://github.com/mariansimecek/sveltejs-kit-template-default-wfzvwb
stackblitz (error is different, becouse of webcontainers?)
https://stackblitz.com/~/github.com/mariansimecek/sveltejs-kit-template-default-wfzvwb

Logs

ReferenceError: snippet is not defined
    at _page (/home/mariansimecek/dev/sveltejs-kit-template-default-wfzvwb/src/routes/+page.svelte:5:19)
    at /home/mariansimecek/dev/sveltejs-kit-template-default-wfzvwb/.svelte-kit/generated/root.svelte:45:41
    at Module.slot (/home/mariansimecek/dev/sveltejs-kit-template-default-wfzvwb/node_modules/svelte/src/internal/server/index.js:537:3)
    at _layout (/home/mariansimecek/dev/sveltejs-kit-template-default-wfzvwb/src/routes/+layout.svelte:8:4)
    at Root (/home/mariansimecek/dev/sveltejs-kit-template-default-wfzvwb/.svelte-kit/generated/root.svelte:44:40)
    at Module.render (/home/mariansimecek/dev/sveltejs-kit-template-default-wfzvwb/node_modules/svelte/src/internal/server/index.js:199:2)
    at Function._render [as render] (/home/mariansimecek/dev/sveltejs-kit-template-default-wfzvwb/node_modules/svelte/src/legacy/legacy-server.js:26:18)
    at Module.render_response (/home/mariansimecek/dev/sveltejs-kit-template-default-wfzvwb/node_modules/@sveltejs/kit/src/runtime/server/page/render.js:171:29)
    at async Module.render_page (/home/mariansimecek/dev/sveltejs-kit-template-default-wfzvwb/node_modules/@sveltejs/kit/src/runtime/server/page/index.js:286:10)
    at async resolve (/home/mariansimecek/dev/sveltejs-kit-template-default-wfzvwb/node_modules/@sveltejs/kit/src/runtime/server/respond.js:446:18)

System Info

System:
    OS: Linux 6.7 Fedora Linux 39 (Workstation Edition)
    CPU: (8) x64 Intel(R) Core(TM) i5-8300H CPU @ 2.30GHz
    Memory: 6.80 GB / 15.48 GB
    Container: Yes
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
    npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm
  Browsers:
    Chrome: 123.0.6312.86
  npmPackages:
    svelte: ^5.0.0-next.95 => 5.0.0-next.95 
    @sveltejs/kit: ^2.5.5

Severity

blocking an upgrade

@trueadm
Copy link
Contributor

trueadm commented Apr 9, 2024

I'm unable to see any issues here locally or when I move it to the REPL. Going to assume it's been fixed since.

@trueadm trueadm closed this as completed Apr 9, 2024
@dummdidumm
Copy link
Member

I can reproduce this

@dummdidumm dummdidumm reopened this Apr 9, 2024
@dummdidumm dummdidumm self-assigned this Apr 9, 2024
@dummdidumm dummdidumm added this to the 5.0 milestone Apr 9, 2024
dummdidumm added a commit that referenced this issue Apr 9, 2024
…prop

...by hoisting top level snippets out of the binding loop in ssr mode
fixes #11086
Rich-Harris pushed a commit that referenced this issue Apr 10, 2024
…prop (#11104)

...by hoisting top level snippets out of the binding loop in ssr mode
fixes #11086
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.

3 participants