-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Conditionally rendered default <slot {prop}>
with unrelated named <slot>
causes unexpected let:prop
assignment
#6901
Comments
I believe the reason why the headeranddata = new HeaderAndData({
props: {
$$slots: {
default: [
create_default_slot,
({ data: { hello } }) => ({ 0: hello }),
({ data: hello_hello }) => hello_hello ? 1 : 0
]
},
$$scope: { ctx }
}
}); There's more to it, of course, but that's the relevant part. The slot data structure consists of an array of three functions; I haven't delved into what they do in detail, but you can see that the second function expects to receive an object with a Now, if you uncomment the headeranddata = new HeaderAndData({
props: {
$$slots: {
header: [
create_header_slot,
({ data: { hello } }) => ({ 0: hello }),
({ data: hello_hello }) => hello_hello ? 1 : 0
],
default: [
create_default_slot,
({ data: { hello } }) => ({ 0: hello }),
({ data: hello_hello }) => hello_hello ? 1 : 0
]
},
$$scope: { ctx }
}
}); Note how the <FancyListExample let:item={foo}>
<div slot="header">{foo.title}</div>
<div>{foo.body}</div>
<div slot="footer">{foo.endnotes}</div>
</FancyListExample> If the Now, let's get back to your REPL example. It looks like as long as the default slot is the only slot, and it isn't being rendered in the component, the There are two ways you could solve this. The simplest way is to not deference <HeaderAndData let:data={data}>
<!-- Uncommented header line now does not throw exception -->
<h1 slot="header">Data:</h1>
<p>{data.hello}</p>
</HeaderAndData> And then, of course, you could just use the The other thing you could do is assign a default value to Which one of those two fixes is better for you depends on what your real code is doing, but in general I think the first approach (don't destructure |
Seems like this has been fixed in version 4... likely by #6049 @darrylyeo can you check if you're still around? |
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 errorCannot read property 'hello' of undefined
whenever the variable is consumed withlet:
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
HeaderAndData.svelte
Logs
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: