2022-04-06 19:42:01 +00:00
|
|
|
import { sharedConfig } from 'solid-js';
|
2022-03-18 22:35:45 +00:00
|
|
|
import { hydrate, createComponent } from 'solid-js/web';
|
|
|
|
|
|
|
|
export default (element) => (Component, props, childHTML) => {
|
2022-04-19 18:37:27 +00:00
|
|
|
// Prepare global object expected by Solid's hydration logic
|
|
|
|
if (!window._$HY) {
|
2022-04-19 18:38:14 +00:00
|
|
|
window._$HY = { events: [], completed: new WeakSet(), r: {} };
|
2022-04-19 18:37:27 +00:00
|
|
|
}
|
|
|
|
// Perform actual hydration
|
2022-03-18 22:35:45 +00:00
|
|
|
let children;
|
2022-04-06 19:42:01 +00:00
|
|
|
hydrate(
|
|
|
|
() =>
|
|
|
|
createComponent(Component, {
|
|
|
|
...props,
|
|
|
|
get children() {
|
|
|
|
if (childHTML != null) {
|
|
|
|
// hydrating
|
|
|
|
if (sharedConfig.context) children = element.querySelector('astro-fragment');
|
2022-03-18 22:35:45 +00:00
|
|
|
|
2022-04-06 19:42:01 +00:00
|
|
|
if (children == null) {
|
|
|
|
children = document.createElement('astro-fragment');
|
|
|
|
children.innerHTML = childHTML;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return children;
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
element
|
|
|
|
);
|
2022-03-18 22:35:45 +00:00
|
|
|
};
|