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-12-22 21:11:05 +00:00
|
|
|
if (typeof Component !== 'function') return false;
|
|
|
|
try {
|
|
|
|
const { html } = renderToStaticMarkup(Component, props, children);
|
|
|
|
return typeof html === 'string';
|
|
|
|
} catch (err) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-07-21 23:10:03 +00:00
|
|
|
}
|
|
|
|
|
2021-10-05 16:20:51 +00:00
|
|
|
function renderToStaticMarkup(Component, props, children) {
|
2021-12-22 21:11:05 +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: children != null ? ssr(`<astro-fragment>${children}</astro-fragment>`) : children,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
return { html: html + `<script>window._$HYDRATION||(window._$HYDRATION={events:[],completed:new WeakSet})</script>` };
|
2021-07-21 23:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
2021-12-22 21:11:05 +00:00
|
|
|
check,
|
|
|
|
renderToStaticMarkup,
|
2021-07-21 23:10:03 +00:00
|
|
|
};
|