-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Closed as not planned
Description
Describe the problem
Svelte 4 had a simple syntax to define the slot default code :
<slot>
<!-- Default code if slot is missing -->
</slot>Svelte 5 doesn't really have an equivalent for that, and this has to be done manually :
Either via an if/else :
{#if children}
{@render children()}
{:else}
<!-- Default code if children is missing -->
{:if}Or via a second snippet :
{#snippet default_children()}
<!-- Default code if children is missing -->
{/snippet}
{@render (children??default_children)()}Describe the proposed solution
It would be nice to have a {#render} block that would mimic the <slot/> behavior :
{#render children()}
<!-- Default code if children is missing -->
{/render}]I think that this change may only impact the compiler, as the result code could simply use $.snippet() with a condition :
$.snippet(node, () => $$props.children ?? ($$anchor) => {
$.next();
var text_1 = $.text("DEFAULT CHILDREN");
$.append($$anchor, text_1);
});If the idea is accepted, I think I could try to implement it...
Importance
nice to have
Metadata
Metadata
Assignees
Labels
No labels