svelte: No error for `@render undefined` if snippet function is state
Describe the bug
Currently, @render has no problem if it the snippet function is undefined if it’s a state/prop, which is weird since it is a function call. Considering the {@render func?.() syntax is supported, it should throw.
<script>
let func = $state()
$effect(() => {
console.log(func === undefined) // true
});
</script>
This doesn't throw: {@render func()}
<script>
let func
console.log(func === undefined) // true
</script>
This is an error: {@render func()}
Severity
annoyance
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (16 by maintainers)
I’m torn. I know in other situations we are erring on the side of rendering nothing. I don’t know whether we want to say that we should error here because the syntax looks like a function invocation.
In a similar vein, if
Foois undefined, then<svelte:component this={Foo}/>renders nothing (as does<svelte:element this={Foo}/>), while<Foo/>is a runtime error. I don’t know. We have varying behavior here, but all of these things feel like the same sort of thing to me as rendering a snippet, regardless of whether it’s a function-like syntax.