fix: Nested hydration with Solid (#3003)
* fix: solid nested hydration * Create ten-rice-unite.md Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
This commit is contained in:
parent
debdf11b19
commit
13b782f421
3 changed files with 44 additions and 16 deletions
6
.changeset/ten-rice-unite.md
Normal file
6
.changeset/ten-rice-unite.md
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
"@astrojs/solid-js": patch
|
||||||
|
"@astrojs/renderer-solid": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Improve nested hydration with Solid
|
|
@ -1,14 +1,25 @@
|
||||||
|
import { sharedConfig } from 'solid-js';
|
||||||
import { hydrate, createComponent } from 'solid-js/web';
|
import { hydrate, createComponent } from 'solid-js/web';
|
||||||
|
|
||||||
export default (element) => (Component, props, childHTML) => {
|
export default (element) => (Component, props, childHTML) => {
|
||||||
let children;
|
let children;
|
||||||
if (childHTML != null) {
|
hydrate(
|
||||||
children = document.createElement('astro-fragment');
|
() =>
|
||||||
children.innerHTML = childHTML;
|
createComponent(Component, {
|
||||||
}
|
...props,
|
||||||
|
get children() {
|
||||||
|
if (childHTML != null) {
|
||||||
|
// hydrating
|
||||||
|
if (sharedConfig.context) children = element.querySelector('astro-fragment');
|
||||||
|
|
||||||
// Using Solid's `hydrate` method ensures that a `root` is created
|
if (children == null) {
|
||||||
// in order to properly handle reactivity. It also handles
|
children = document.createElement('astro-fragment');
|
||||||
// components that are not native HTML elements.
|
children.innerHTML = childHTML;
|
||||||
hydrate(() => createComponent(Component, { ...props, children }), element);
|
}
|
||||||
|
}
|
||||||
|
return children;
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
element
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,14 +1,25 @@
|
||||||
|
import { sharedConfig } from 'solid-js';
|
||||||
import { hydrate, createComponent } from 'solid-js/web';
|
import { hydrate, createComponent } from 'solid-js/web';
|
||||||
|
|
||||||
export default (element) => (Component, props, childHTML) => {
|
export default (element) => (Component, props, childHTML) => {
|
||||||
let children;
|
let children;
|
||||||
if (childHTML != null) {
|
hydrate(
|
||||||
children = document.createElement('astro-fragment');
|
() =>
|
||||||
children.innerHTML = childHTML;
|
createComponent(Component, {
|
||||||
}
|
...props,
|
||||||
|
get children() {
|
||||||
|
if (childHTML != null) {
|
||||||
|
// hydrating
|
||||||
|
if (sharedConfig.context) children = element.querySelector('astro-fragment');
|
||||||
|
|
||||||
// Using Solid's `hydrate` method ensures that a `root` is created
|
if (children == null) {
|
||||||
// in order to properly handle reactivity. It also handles
|
children = document.createElement('astro-fragment');
|
||||||
// components that are not native HTML elements.
|
children.innerHTML = childHTML;
|
||||||
hydrate(() => createComponent(Component, { ...props, children }), element);
|
}
|
||||||
|
}
|
||||||
|
return children;
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
element
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue