You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the docs, the only mention of snippets-slots interop is:
In Svelte 4, content can be passed to components using slots. Svelte 5 replaces them with snippets which are more powerful and flexible, and as such slots are deprecated in Svelte 5.
They continue to work, however, and you can mix and match snippets and slots in your components.
But it doesn't say exactly what that means. It is intuitive that you can use old components with slots from new snippet-based components, but not the other way around, and that slot props are passed using destructuring, as they are named, but I think this should be documented a bit.
<!-- Child.svelte -->
<script>
let value =0
</script>
<slotname="named" {value} />
<br>
<slot {value} />
<br>
<buttonon:click={() =>value++}>Increment</button>
<!-- Parent.svelte -->
<Child>
{#snippetnamed({ value })}
Named: {value}
{/snippet}
{#snippetchildren({ value })}
Default with value: {value}
{/snippet}
</Child>
But the other way around doesn't work (except for default slots and without props), as it doesn't make sense to write Svelte 4 code using Svelte 5 code, but I think it can happen if upgrading to Svelte 5 libraries in a codebase that's not fully migrated:
<!-- Child.svelte -->
<script>
let { children, named } =$props()
</script>
{@renderchildren?.()}
<br>
{@rendernamed?.()}
<!-- Parent.svelte -->
<Child>
<!-- This doesn't get rendered -->
<svelte:fragmentslot="named">
Named
</svelte:fragment>
Default
</Child>
<!-- Child.svelte -->
<script>
let { children, named } =$props()
</script>
{@renderchildren?.({ value: 123 })}
<!-- Parent.svelte --><!-- invalid_default_snippet Cannot use `{@render children(...)}` if the parent component uses `let:` directives. Consider using a named snippet instead in New.svelte in App.svelte -->
<Childlet:value>
Value: {value}
</Child>
The text was updated successfully, but these errors were encountered:
Describe the bug
In the docs, the only mention of snippets-slots interop is:
But it doesn't say exactly what that means. It is intuitive that you can use old components with slots from new snippet-based components, but not the other way around, and that slot props are passed using destructuring, as they are named, but I think this should be documented a bit.
For example:
And with values:
But the other way around doesn't work (except for default slots and without props), as it doesn't make sense to write Svelte 4 code using Svelte 5 code, but I think it can happen if upgrading to Svelte 5 libraries in a codebase that's not fully migrated:
Or:
The text was updated successfully, but these errors were encountered: