aboutsummaryrefslogtreecommitdiff
path: root/packages/renderers/renderer-solid/server.js
blob: 8af4d8aab91df73410fed048b27a1c904fef3572 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { createComponent } from 'solid-js';
import { renderToStringAsync, ssr } from 'solid-js/web/dist/server.js';

async function check(Component, props, children) {
  if (typeof Component !== 'function') return false;

  const { html } = await renderToStaticMarkup(Component, props, children);
  return typeof html === 'string';
}

async function renderToStaticMarkup(Component, props, children) {
  const html = await renderToStringAsync(() => (
    () => createComponent(Component, {
      ...props,
      // In Solid SSR mode, `ssr` creates the expected structure for `children`.
      // In Solid client mode, `ssr` is just a stub.
      children: ssr([`<astro-fragment>${children}</astro-fragment>`]),
    })
  ));
  return { html };
}

export default {
  check,
  renderToStaticMarkup,
};