2021-10-05 16:20:51 +00:00
|
|
|
import { renderToString, ssr, createComponent } from 'solid-js/web/dist/server.js';
|
2021-07-21 23:10:03 +00:00
|
|
|
|
2021-10-05 16:20:51 +00:00
|
|
|
function check(Component, props, children) {
|
2021-07-21 23:10:03 +00:00
|
|
|
if (typeof Component !== 'function') return false;
|
|
|
|
|
2021-10-05 16:20:51 +00:00
|
|
|
const { html } = renderToStaticMarkup(Component, props, children);
|
2021-07-21 23:10:03 +00:00
|
|
|
return typeof html === 'string';
|
|
|
|
}
|
|
|
|
|
2021-10-05 16:20:51 +00:00
|
|
|
function renderToStaticMarkup(Component, props, children) {
|
2021-10-05 16:22:58 +00:00
|
|
|
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>`),
|
|
|
|
})
|
2021-07-21 23:11:40 +00:00
|
|
|
);
|
2021-10-05 16:20:51 +00:00
|
|
|
return { html: html + `<script>window._$HYDRATION||(window._$HYDRATION={events:[],completed:new WeakSet})</script>` };
|
2021-07-21 23:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
check,
|
|
|
|
renderToStaticMarkup,
|
|
|
|
};
|