2022-04-06 19:42:01 +00:00
|
|
|
import { sharedConfig } from 'solid-js';
|
2022-05-31 16:29:36 +00:00
|
|
|
import { hydrate, render, createComponent } from 'solid-js/web';
|
2022-03-18 22:35:45 +00:00
|
|
|
|
2022-05-31 16:47:13 +00:00
|
|
|
export default (element) =>
|
|
|
|
(Component, props, childHTML, { client }) => {
|
|
|
|
// Prepare global object expected by Solid's hydration logic
|
|
|
|
if (!window._$HY) {
|
|
|
|
window._$HY = { events: [], completed: new WeakSet(), r: {} };
|
|
|
|
}
|
|
|
|
if (!element.hasAttribute('ssr')) return;
|
2022-05-31 16:29:36 +00:00
|
|
|
|
2022-05-31 16:47:13 +00:00
|
|
|
const fn = client === 'only' ? render : hydrate;
|
|
|
|
|
|
|
|
// Perform actual hydration
|
|
|
|
let children;
|
|
|
|
fn(
|
|
|
|
() =>
|
|
|
|
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-05-31 16:47:13 +00:00
|
|
|
if (children == null) {
|
|
|
|
children = document.createElement('astro-fragment');
|
|
|
|
children.innerHTML = childHTML;
|
|
|
|
}
|
2022-04-06 19:42:01 +00:00
|
|
|
}
|
2022-05-31 16:47:13 +00:00
|
|
|
return children;
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
element
|
|
|
|
);
|
|
|
|
};
|