summaryrefslogtreecommitdiff
path: root/packages/renderers/renderer-solid/client.js
blob: 815f3d8e5bab9d381bd992c0c03a75b1c75a6434 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { createComponent } from 'solid-js';
import { render } from 'solid-js/web';

export default (element) => (Component, props, childHTML) => {
  // Solid's `render` does not replace the element's children.
  // Deleting the root's children is necessary before calling `render`.
  element.replaceChildren();

  const children = document.createElement('astro-fragment');
  children.innerHTML = childHTML;

  // Using Solid's `render` method ensures that a `root` is created
  // in order to properly handle reactivity. It also handles
  // components that are not native HTML elements.
  render(() => createComponent(Component, { ...props, children }), element);
};