-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
Describe the bug
Context: Migrating components that manage other components from a slots implementation to a snippets implementation.
Problem I will suggest below that something worthwhile is being lost in the translation.
My example is a Hoverable component. It's job is to render some content-A, and then when that is hovered-over, to position and show content-B, as a drop-down content beneath it.
Before
<Hoverable>
<span slot="hotspot" class="avatar">person</span>
<UserDropDown slot="content" />
</Hoverable>
After
{#snippet hotspotSnip()}<span class="avatar">person</span>{/snippet}
{#snippet contentSnip()}<UserDropDown />{/snippet}
<Hov2 hotspot={hotspotSnip} content={contentSnip} />
I would argue that the snippet version:
- Loses the valuable implied parent/child/container essence of the slots version
- Obliges the reader to absorb all 3 lines of code, when they might be quite satisfied to see that "it's just some Hoverable".
- Obliges the writer to invent two new names and avoid mistakes in their transcription.
Additional Notes
It could be reduced to a much simpler container component if the children were constrained to be fully fledged components - because then neither slots, nor snippets would be required. The children could be passed in as props very easily in Svelte5. But being able to "pass in" arbitrary content (like the span in my example) is available with slots, and is a documented design goal for snippets.
I'd like to acknowledge the fabulous help I received on solving a problem with the snippets version here.
Apologies if I'm missing another way to skin this particular cat. There's a lot to take on board migrating to Svelte5. (Particularly if you're really a Go developer).
Reproduction
There are before and after working examples in the Svelte REPL referenced in the "fabulous help" link above.
Logs
n/aSystem Info
n/aSeverity
annoyance