-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Nested hydration with Solid (#3003)
* fix: solid nested hydration * Create ten-rice-unite.md Co-authored-by: Nate Moore <[email protected]>
- Loading branch information
1 parent
debdf11
commit 13b782f
Showing
3 changed files
with
44 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@astrojs/solid-js": patch | ||
"@astrojs/renderer-solid": patch | ||
--- | ||
|
||
Improve nested hydration with Solid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,25 @@ | ||
import { sharedConfig } from 'solid-js'; | ||
import { hydrate, createComponent } from 'solid-js/web'; | ||
|
||
export default (element) => (Component, props, childHTML) => { | ||
let children; | ||
if (childHTML != null) { | ||
children = document.createElement('astro-fragment'); | ||
children.innerHTML = childHTML; | ||
} | ||
hydrate( | ||
() => | ||
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 | ||
// in order to properly handle reactivity. It also handles | ||
// components that are not native HTML elements. | ||
hydrate(() => createComponent(Component, { ...props, children }), element); | ||
if (children == null) { | ||
children = document.createElement('astro-fragment'); | ||
children.innerHTML = childHTML; | ||
} | ||
} | ||
return children; | ||
}, | ||
}), | ||
element | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,25 @@ | ||
import { sharedConfig } from 'solid-js'; | ||
import { hydrate, createComponent } from 'solid-js/web'; | ||
|
||
export default (element) => (Component, props, childHTML) => { | ||
let children; | ||
if (childHTML != null) { | ||
children = document.createElement('astro-fragment'); | ||
children.innerHTML = childHTML; | ||
} | ||
hydrate( | ||
() => | ||
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 | ||
// in order to properly handle reactivity. It also handles | ||
// components that are not native HTML elements. | ||
hydrate(() => createComponent(Component, { ...props, children }), element); | ||
if (children == null) { | ||
children = document.createElement('astro-fragment'); | ||
children.innerHTML = childHTML; | ||
} | ||
} | ||
return children; | ||
}, | ||
}), | ||
element | ||
); | ||
}; |