Description
Describe the bug
I am pretty sure this is not necessarily a bug but an intended behaviour. However, the error given is so vague, and I could not find any documentation explaining why this functionality is not supported. Given is the following snippet:
<script lang="ts">
import type { Snippet } from 'svelte';
function formatter(v: number): ReturnType<Snippet<[number, string]>> {
return draw(v, 'pink');
}
</script>
{@render draw(0, 'orange')}
{@render formatter(0)} <!-- ERROR: Value is not a function error-->
{#snippet draw(value: number, color: string)}
<p>
value:
<span style="background:{color}">
{value}
</span>
</p>
{/snippet}
I try to create a new snippet that only takes part of an original snippet. Type wise this should be supported as draw
has the following typing:
const draw: (value: number, color: string) => ReturnType<import("svelte").Snippet>
My expectation was that formatter
would behave similarly to the following
{#snippet formatter(value: number)}
{@render draw(value, 'pink')}
{/snippet}
The browser complains with a strange error which I have never encountered before. I suspect it has something to do with component mounting, unmounting or scoping? What part of Svelte magic am I missing in order to understand this error? Would this behaviour be possible with createRawSnippet?
Reproduction
https://svelte.dev/playground/33470f759ec0434cbcb597f5119a36da?version=5.2.11
Logs
No response
System Info
System:
OS: macOS 15.1.1
CPU: (8) arm64 Apple M1 Pro
Memory: 146.22 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.2.0 - ~/.nvm/versions/node/v22.2.0/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.7.0 - ~/.nvm/versions/node/v22.2.0/bin/npm
pnpm: 9.14.4 - ~/Library/pnpm/pnpm
bun: 1.1.8 - ~/.bun/bin/bun
Browsers:
Chrome: 131.0.6778.86
Safari: 18.1.1
npmPackages:
svelte: ^5.0.0 => 5.1.16
Severity
annoyance