Skip to content

Commit d423004

Browse files
fix: avoid migrating slots in custom elements (#13406)
They'll be preserved as-is in some future Svelte version
1 parent 30c438c commit d423004

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

.changeset/eight-waves-mate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: avoid migrating slots in custom elements

packages/svelte/src/compiler/migrate/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ const template = {
599599
next();
600600
},
601601
SlotElement(node, { state, next }) {
602+
if (state.analysis.custom_element) return;
602603
let name = 'children';
603604
let slot_name = 'default';
604605
let slot_props = '{ ';
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<svelte:options customElement="my-element" />
2+
3+
<script>
4+
// to show that it doesn't bail out from the whole migration
5+
let count = 0;
6+
</script>
7+
8+
<button on:click={()=>count++}><slot /></button>
9+
10+
{count}
11+
12+
{#if foo}
13+
<slot name="foo" {foo} />
14+
{/if}
15+
16+
{#if $$slots.bar}
17+
{$$slots}
18+
<slot name="bar" />
19+
{/if}
20+
21+
{#if $$slots.default}foo{/if}
22+
23+
<slot name="dashed-name" />
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<svelte:options customElement="my-element" />
2+
3+
<script>
4+
// to show that it doesn't bail out from the whole migration
5+
let count = $state(0);
6+
</script>
7+
8+
<button onclick={()=>count++}><slot /></button>
9+
10+
{count}
11+
12+
{#if foo}
13+
<slot name="foo" {foo} />
14+
{/if}
15+
16+
{#if bar}
17+
{$$slots}
18+
<slot name="bar" />
19+
{/if}
20+
21+
{#if children}foo{/if}
22+
23+
<slot name="dashed-name" />

0 commit comments

Comments
 (0)