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