fix: avoid migrating slots in custom elements (#13406)

They'll be preserved as-is in some future Svelte version
pull/13394/head
Paolo Ricciuti 2 months ago committed by GitHub
parent 30c438c279
commit d4230049da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: avoid migrating slots in custom elements

@ -599,6 +599,7 @@ const template = {
next();
},
SlotElement(node, { state, next }) {
if (state.analysis.custom_element) return;
let name = 'children';
let slot_name = 'default';
let slot_props = '{ ';

@ -0,0 +1,23 @@
<svelte:options customElement="my-element" />
<script>
// to show that it doesn't bail out from the whole migration
let count = 0;
</script>
<button on:click={()=>count++}><slot /></button>
{count}
{#if foo}
<slot name="foo" {foo} />
{/if}
{#if $$slots.bar}
{$$slots}
<slot name="bar" />
{/if}
{#if $$slots.default}foo{/if}
<slot name="dashed-name" />

@ -0,0 +1,23 @@
<svelte:options customElement="my-element" />
<script>
// to show that it doesn't bail out from the whole migration
let count = $state(0);
</script>
<button onclick={()=>count++}><slot /></button>
{count}
{#if foo}
<slot name="foo" {foo} />
{/if}
{#if bar}
{$$slots}
<slot name="bar" />
{/if}
{#if children}foo{/if}
<slot name="dashed-name" />
Loading…
Cancel
Save