diff options
author | 2023-05-17 10:18:04 -0400 | |
---|---|---|
committer | 2023-05-17 10:18:04 -0400 | |
commit | 3d525efc95cfb2deb5d9e04856d02965d66901c9 (patch) | |
tree | af1973aede0d2950d94b7ebfc957770be214446c /packages/integrations/svelte/server.js | |
parent | e9fc2c2213036d47cd30a47a6cdad5633481a0f8 (diff) | |
download | astro-3d525efc95cfb2deb5d9e04856d02965d66901c9.tar.gz astro-3d525efc95cfb2deb5d9e04856d02965d66901c9.tar.zst astro-3d525efc95cfb2deb5d9e04856d02965d66901c9.zip |
Prevent removal of nested slots within islands (#7093)
* Prevent removal of nested slots within islands
* Fix build errors
Diffstat (limited to 'packages/integrations/svelte/server.js')
-rw-r--r-- | packages/integrations/svelte/server.js | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/packages/integrations/svelte/server.js b/packages/integrations/svelte/server.js index 98ece3314..9878d3b59 100644 --- a/packages/integrations/svelte/server.js +++ b/packages/integrations/svelte/server.js @@ -2,11 +2,17 @@ function check(Component) { return Component['render'] && Component['$$render']; } -async function renderToStaticMarkup(Component, props, slotted) { +function needsHydration(metadata) { + // Adjust how this is hydrated only when the version of Astro supports `astroStaticSlot` + return metadata.astroStaticSlot ? !!metadata.hydrate : true; +} + +async function renderToStaticMarkup(Component, props, slotted, metadata) { + const tagName = needsHydration(metadata) ? 'astro-slot' : 'astro-static-slot'; const slots = {}; for (const [key, value] of Object.entries(slotted)) { slots[key] = () => - `<astro-slot${key === 'default' ? '' : ` name="${key}"`}>${value}</astro-slot>`; + `<${tagName}${key === 'default' ? '' : ` name="${key}"`}>${value}</${tagName}>`; } const { html } = Component.render(props, { $$slots: slots }); return { html }; @@ -15,4 +21,5 @@ async function renderToStaticMarkup(Component, props, slotted) { export default { check, renderToStaticMarkup, + supportsAstroStaticSlot: true, }; |