sveltejs / svelte

Cybernetically enhanced web apps
https://svelte.dev
MIT License
78.04k stars 4.08k forks source link

Svelte5: Snippet block name conflict with component name causes error #12006

Closed thelostword closed 2 months ago

thelostword commented 2 months ago

Describe the bug

When using a snippet block in Svelte 5, if the snippet block name is the same as the component name, it causes an error. This issue arises when trying to reuse the component within the snippet block.

Steps to Reproduce

  1. Create a Svelte component named DemoTempChild.
  2. Use the following snippet block syntax in a parent component:
{#snippet DemoTempChild(item)}
  <DemoTempChild data={item}></DemoTempChild>
{/snippet}

Reproduction

REPL: https://svelte-5-preview-svelte.vercel.app

Logs

image

System Info

System:
    OS: Windows 11 10.0.22621
    CPU: (16) x64 12th Gen Intel(R) Core(TM) i5-1240P
    Memory: 4.75 GB / 15.73 GB
  Binaries:
    Node: 18.17.1 - ~\AppData\Local\Volta\tools\image\node\18.17.1\node.EXE
    npm: 9.6.7 - ~\AppData\Local\Volta\tools\image\node\18.17.1\npm.CMD
    pnpm: 8.7.5 - C:\Program Files\Volta\pnpm.EXE
    bun: 1.1.12 - ~\.bun\bin\bun.EXE
  Browsers:
    Edge: Chromium (125.0.2535.92)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    svelte: ^5.0.0-next.153 => 5.0.0-next.153

Severity

annoyance

dummdidumm commented 2 months ago

This works as expected. You can access the snippet within the snippet, to for example to recursive rendering. Think of a snippet as a function definition - inside its scope the function is callable, too. Therefore closing.