astro/packages/renderers/renderer-solid/server.js
Drew Powers 330620e1b3 Update renderer API for Vite (#1623)
* Update renderer API for Vite

* Fix lit-element tests

* Clean up comments

* Throw friendly error if renderer provides viteConfig in a bad format
2021-10-22 16:25:38 -06:00

25 lines
828 B
JavaScript

import { renderToString, ssr, createComponent } from 'solid-js/web/dist/server.js';
function check(Component, props, children) {
if (typeof Component !== 'function') return false;
const { html } = renderToStaticMarkup(Component, props, children);
return typeof html === 'string';
}
function renderToStaticMarkup(Component, props, children) {
const html = renderToString(() =>
createComponent(Component, {
...props,
// In Solid SSR mode, `ssr` creates the expected structure for `children`.
// In Solid client mode, `ssr` is just a stub.
children: ssr(`<astro-fragment>${children}</astro-fragment>`),
})
);
return { html: html + `<script>window._$HYDRATION||(window._$HYDRATION={events:[],completed:new WeakSet})</script>` };
}
export default {
check,
renderToStaticMarkup,
};