mirror of
https://github.com/withastro/astro.git
synced 2024-12-23 21:53:55 -05:00
abc5b219bb
* Remove try/catch from solid component check * Move try/catch to renderComponent * Add solid to integrations-playground example
26 lines
726 B
JavaScript
26 lines
726 B
JavaScript
import { renderToString, ssr, createComponent } from 'solid-js/web';
|
|
|
|
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: children != null ? ssr(`<astro-fragment>${children}</astro-fragment>`) : children,
|
|
})
|
|
);
|
|
return {
|
|
html: html,
|
|
};
|
|
}
|
|
|
|
export default {
|
|
check,
|
|
renderToStaticMarkup,
|
|
};
|