Describe the bug
I have a component that passes a variable to the default <slot>
, which should only be rendered if the variable is defined. However, adding an additional unrelated named <slot>
causes an error Cannot read property 'hello' of undefined
whenever the variable is consumed with let:
destructuring syntax.
I would expect let:
to not be assigned to if the default <slot>
isn't being rendered, regardless of the presence of additional named slots.
Reproduction
REPL: https://svelte.dev/repl/a7df02836b344eab9db7e3f01b7ec43f?version=3.44.1
App.svelte
<script>
import HeaderAndData from './HeaderAndData.svelte'
</script>
<HeaderAndData let:data={{hello}}>
<!-- Uncomment this (Cannot read property 'hello' of undefined) -->
<!-- <h1 slot="header">Data:</h1> -->
<p>{hello}</p>
</HeaderAndData>
HeaderAndData.svelte
<script>
let data
function getData(){
data = {
hello: 'world'
}
}
</script>
<button on:click={getData}>Get Data</button>
<slot name="header"></slot>
{#if data}
<slot {data}></slot>
{/if}
Logs
Cannot read property 'hello' of undefined
System Info
Severity
annoyance