2022-03-18 15:35:45 -07:00
|
|
|
import { renderToString, ssr, createComponent } from 'solid-js/web';
|
|
|
|
|
|
|
|
function check(Component, props, children) {
|
|
|
|
if (typeof Component !== 'function') return false;
|
2022-05-11 12:23:34 -04:00
|
|
|
const { html } = renderToStaticMarkup(Component, props, children);
|
|
|
|
return typeof html === 'string';
|
2022-03-18 15:35:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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: children != null ? ssr(`<astro-fragment>${children}</astro-fragment>`) : children,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
return {
|
2022-04-19 20:37:27 +02:00
|
|
|
html: html,
|
2022-03-18 15:35:45 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
check,
|
|
|
|
renderToStaticMarkup,
|
|
|
|
};
|