Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use dynamic components in root.svelte instead of svelte:component for svelte 5 #12584

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cyan-hounds-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: use dynamic components in `root.svelte` instead of `svelte:component` for svelte 5
37 changes: 29 additions & 8 deletions packages/kit/src/core/sync/write_root.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,39 @@ export function write_root(manifest_data, output) {
let l = max_depth;

let pyramid = dedent`
${isSvelte5Plus() ? '<!-- svelte-ignore binding_property_non_reactive -->' : ''}
<svelte:component this={constructors[${l}]} bind:this={components[${l}]} data={data_${l}} {form} />
`;
${
isSvelte5Plus()
? `<!-- svelte-ignore binding_property_non_reactive -->
<Pyramid_${l} bind:this={components[${l}]} data={data_${l}} {form} />`
: `<svelte:component this={constructors[${l}]} bind:this={components[${l}]} data={data_${l}} {form} />`
}`;

while (l--) {
pyramid = dedent`
{#if constructors[${l + 1}]}
${isSvelte5Plus() ? '<!-- svelte-ignore binding_property_non_reactive -->' : ''}
<svelte:component this={constructors[${l}]} bind:this={components[${l}]} data={data_${l}}>
${
isSvelte5Plus()
? dedent`{@const Pyramid_${l} = constructors[${l}]}
<!-- svelte-ignore binding_property_non_reactive -->
<Pyramid_${l} bind:this={components[${l}]} data={data_${l}} {form}>
${pyramid}
</Pyramid_${l}>`
: dedent`<svelte:component this={constructors[${l}]} bind:this={components[${l}]} data={data_${l}}>
${pyramid}
</svelte:component>
</svelte:component>`
}

{:else}
${isSvelte5Plus() ? '<!-- svelte-ignore binding_property_non_reactive -->' : ''}
<svelte:component this={constructors[${l}]} bind:this={components[${l}]} data={data_${l}} {form} />
${
isSvelte5Plus()
? dedent`
{@const Pyramid_${l} = constructors[${l}]}
<!-- svelte-ignore binding_property_non_reactive -->
<Pyramid_${l} bind:this={components[${l}]} data={data_${l}} {form} />
`
: dedent`<svelte:component this={constructors[${l}]} bind:this={components[${l}]} data={data_${l}} {form} />`
}

{/if}
`;
}
Expand Down Expand Up @@ -111,6 +130,8 @@ export function write_root(manifest_data, output) {
mounted = true;
return unsubscribe;
});

${isSvelte5Plus() ? `const Pyramid_${max_depth}=$derived(constructors[${max_depth}])` : ''}
</script>

${pyramid}
Expand Down
Loading