0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00
astro/packages/integrations/vue/server.js
Emanuele Stoppa dfd146f591
Revert "[ci] format" (#10417)
* Revert "[ci] format"

This reverts commit 1863727215.

* pin dependency

* update lock
2024-03-13 09:55:24 +00:00

33 lines
1,001 B
JavaScript

import { createSSRApp, h } from 'vue';
import { renderToString } from 'vue/server-renderer';
import StaticHtml from './static-html.js';
import { setup } from 'virtual:@astrojs/vue/app';
function check(Component) {
return !!Component['ssrRender'] || !!Component['__ssrInlineRender'];
}
async function renderToStaticMarkup(Component, inputProps, slotted, metadata) {
const slots = {};
const props = { ...inputProps };
delete props.slot;
for (const [key, value] of Object.entries(slotted)) {
slots[key] = () =>
h(StaticHtml, {
value,
name: key === 'default' ? undefined : key,
// Adjust how this is hydrated only when the version of Astro supports `astroStaticSlot`
hydrate: metadata.astroStaticSlot ? !!metadata.hydrate : true,
});
}
const app = createSSRApp({ render: () => h(Component, props, slots) });
await setup(app);
const html = await renderToString(app);
return { html };
}
export default {
check,
renderToStaticMarkup,
supportsAstroStaticSlot: true,
};