2022-03-18 17:35:45 -05:00
|
|
|
import { renderToString, ssr, createComponent } from 'solid-js/web';
|
|
|
|
|
|
|
|
function check(Component, props, children) {
|
|
|
|
if (typeof Component !== 'function') return false;
|
|
|
|
try {
|
|
|
|
const { html } = renderToStaticMarkup(Component, props, children);
|
|
|
|
return typeof html === 'string';
|
|
|
|
} catch (err) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
})
|
|
|
|
);
|
2022-04-02 15:15:41 -05:00
|
|
|
return {
|
2022-04-19 13:37:27 -05:00
|
|
|
html: html,
|
2022-04-02 15:15:41 -05:00
|
|
|
};
|
2022-03-18 17:35:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
check,
|
|
|
|
renderToStaticMarkup,
|
|
|
|
};
|