0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-06 22:10:10 -05:00
astro/packages/integrations/vue/server.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-04-17 03:38:53 -05:00
import { setup } from 'virtual:@astrojs/vue/app';
import { createSSRApp, h } from 'vue';
import { renderToString } from 'vue/server-renderer';
2024-10-03 13:52:11 -05:00
import { incrementId } from './context.js';
2024-10-03 13:53:02 -05:00
import StaticHtml from './static-html.js';
function check(Component) {
return !!Component['ssrRender'] || !!Component['__ssrInlineRender'];
}
async function renderToStaticMarkup(Component, inputProps, slotted, metadata) {
2024-10-03 13:52:11 -05:00
let prefix;
if (this && this.result) {
prefix = incrementId(this.result);
}
const attrs = { prefix };
const slots = {};
const props = { ...inputProps };
delete props.slot;
for (const [key, value] of Object.entries(slotted)) {
2023-05-17 09:20:24 -05:00
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) });
2024-10-03 13:52:11 -05:00
app.config.idPrefix = prefix;
await setup(app);
const html = await renderToString(app);
2024-10-03 13:52:11 -05:00
return { html, attrs };
}
export default {
name: '@astrojs/vue',
check,
renderToStaticMarkup,
supportsAstroStaticSlot: true,
};