mirror of
https://github.com/withastro/astro.git
synced 2024-12-23 21:53:55 -05:00
1abb9ed080
* chore: unvendor vite * chore: upgrade vue and svelte * feat(renderer-solid): upgrade for vite@2.7.x * chore: update yarn.lock * fix(solid): upgrade solid renderer for vite@2.7.x * test: improve css test * chore: upgrade to vite@2.8.0-beta.3 * fix: replace hacky serialization with 'serialize-javascript' * fix: externalize serialize-javascript * fix: explicitly add execa@6.x.x to devDependencies * test(css): skip css?url test * chore: update vite-plugin-svelte * fix: ssr option * chore: update changeset * chore: remove changeset * chore: add changeset * chore: add back missing changeset * chore: update vite * chore: update to latest vite * test: update proload? * chore: update dependencies * fix: remove preact from nanostores example * fix: update static-build-pkg to use `.mjs` extension * fix: exclude './server.js' from custom-elements test * chore: remove unused file
28 lines
847 B
JavaScript
28 lines
847 B
JavaScript
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,
|
|
})
|
|
);
|
|
return { html: html + `<script>window._$HY||(_$HY={events:[],completed:new WeakSet,r:{}})</script>` };
|
|
}
|
|
|
|
export default {
|
|
check,
|
|
renderToStaticMarkup,
|
|
};
|