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