0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00
astro/packages/renderers/renderer-solid/client.js
Pablo Berganza bef5103ae3
Fix renderer-solid not creating a reactive root (#848)
* use Solid's render method on the client

* add changeset

* use createComponent
2021-07-27 08:51:20 -04:00

16 lines
668 B
JavaScript

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);
};