0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00
astro/packages/integrations/svelte/server.js
Matthew Phillips 3d525efc95
Prevent removal of nested slots within islands (#7093)
* Prevent removal of nested slots within islands

* Fix build errors
2023-05-17 10:18:04 -04:00

25 lines
780 B
JavaScript

function check(Component) {
return Component['render'] && Component['$$render'];
}
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] = () =>
`<${tagName}${key === 'default' ? '' : ` name="${key}"`}>${value}</${tagName}>`;
}
const { html } = Component.render(props, { $$slots: slots });
return { html };
}
export default {
check,
renderToStaticMarkup,
supportsAstroStaticSlot: true,
};