-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Component lifecycle inside <slot>
#903
Comments
Yeah, this is expected behaviour. Basically, there's no way for the parent component to know whether or not the child's |
is it something that could be fixed in the future? The main downside of this I find (apart from memory usage), is consistency. Maybe in the future when we have a central tree of components to support HMR etc. this will start behaving as normal. Closing |
Sorry for bumping this closed issue. I only have a surface level understanding of the Svelte codebase, so I just thought I'd ask if this is even possible to implement? I ask because I was silly and didn't test this thoroughly before I settled on an API for my routing components. |
I'll reopen this issue for now, pending an eventual better-thought-out reply. I think it might be possible — in fact it kinda worked this way when It's supposed to work like <custom-element>
<div slot='foo'>this div always exists, even if there's no corresponding <slot></div>
</custom-element> ...then the custom element has no control over the shadow DOM, beyond adding/removing the |
It's nice being able to use However, as this issue suggests, the extraneous singular creation of There are at least two alternative approaches, but they're not as elegant as wrapper components. To start with, logic could be declared directly within the Alternatively, a wrapper component could not use a I'm not sure how the technical difficulties which have been discussed in this issue could be overcome, though. I would note that, if instant As an aside, I've just seen #1648 and it seems to be about the same topic. |
I'm going to close this, as the behaviour of slots in v3 is essentially what's being discussed here — they are created lazily, whenever the child component needs them. It's a departure from the semantics of |
Components inside
<slot>
are created once, and never destroyed until the main parent component is destroyed.Even when wrapped in
{{#if}}
blocks.Additionally, they are created regardless of whether the guarding
{{#if}}
condition istrue
orfalse
Here is the REPL: https://svelte.technology/repl?version=1.41.1&gist=5234dc5ba4ee472d47b03e55e2ee53bb
Please open the console when you get there.
In the REPL,
Alan
gets created and destroyed as expected, butMike
sticks around(
Mike
andAlan
will make sense when you look at the REPL 😄 )The text was updated successfully, but these errors were encountered: