diff options
author | 2023-12-07 22:47:04 +0800 | |
---|---|---|
committer | 2023-12-07 22:47:04 +0800 | |
commit | 1aa7fe85c1f18fb22e417a1958270443e94cdc32 (patch) | |
tree | abdccd5834a7a0f46ac401301029a14d91ecf49d /packages/integrations/svelte/client-v5.js | |
parent | dfbc7079081d3346713cb536358a3854362a2c95 (diff) | |
download | astro-1aa7fe85c1f18fb22e417a1958270443e94cdc32.tar.gz astro-1aa7fe85c1f18fb22e417a1958270443e94cdc32.tar.zst astro-1aa7fe85c1f18fb22e417a1958270443e94cdc32.zip |
Allow Svelte 5 render slots as snippets (#9285)
Diffstat (limited to 'packages/integrations/svelte/client-v5.js')
-rw-r--r-- | packages/integrations/svelte/client-v5.js | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/packages/integrations/svelte/client-v5.js b/packages/integrations/svelte/client-v5.js index b3d2e1964..eaa06974c 100644 --- a/packages/integrations/svelte/client-v5.js +++ b/packages/integrations/svelte/client-v5.js @@ -1,4 +1,8 @@ import { mount } from 'svelte'; +import { add_snippet_symbol } from 'svelte/internal'; + +// Allow a slot to be rendered as a snippet (dev validation only) +const tagSlotAsSnippet = import.meta.env.DEV ? add_snippet_symbol : (s) => s; export default (element) => { return async (Component, props, slotted) => { @@ -32,7 +36,7 @@ function createSlotDefinition(key, children) { /** * @param {Comment} $$anchor A comment node for slots in Svelte 5 */ - return ($$anchor, _$$slotProps) => { + const fn = ($$anchor, _$$slotProps) => { const parent = $$anchor.parentNode; const el = document.createElement('div'); el.innerHTML = `<astro-slot${ @@ -40,4 +44,5 @@ function createSlotDefinition(key, children) { }>${children}</astro-slot>`; parent.insertBefore(el.children[0], $$anchor); }; + return tagSlotAsSnippet(fn); } |