2022-04-06 14:42:01 -05:00
|
|
|
import { sharedConfig } from 'solid-js';
|
2022-05-31 11:29:36 -05:00
|
|
|
import { hydrate, render, createComponent } from 'solid-js/web';
|
2022-03-18 17:35:45 -05:00
|
|
|
|
2022-05-31 11:29:36 -05:00
|
|
|
export default (element) => (Component, props, childHTML, { client }) => {
|
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
|
|
|
}
|
2022-05-31 11:29:36 -05:00
|
|
|
if (!element.hasAttribute('ssr')) return;
|
|
|
|
|
|
|
|
const fn = client === 'only' ? render : hydrate;
|
|
|
|
|
2022-04-19 13:37:27 -05:00
|
|
|
// Perform actual hydration
|
2022-03-18 17:35:45 -05:00
|
|
|
let children;
|
2022-05-31 11:29:36 -05:00
|
|
|
fn(
|
2022-04-06 14:42:01 -05:00
|
|
|
() =>
|
|
|
|
createComponent(Component, {
|
|
|
|
...props,
|
|
|
|
get children() {
|
|
|
|
if (childHTML != null) {
|
|
|
|
// hydrating
|
2022-05-31 11:29:36 -05:00
|
|
|
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
|
|
|
};
|