Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Nested hydration with Solid #3003

Merged
merged 2 commits into from
Apr 6, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: solid nested hydration
ryansolid committed Apr 6, 2022

Verified

This commit was signed with the committer’s verified signature.
thaJeztah Sebastiaan van Stijn
commit 3224fb8da3965b15bc546154160cdaa3a9c97f9b
27 changes: 19 additions & 8 deletions packages/integrations/solid/client.js
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
);
};
27 changes: 19 additions & 8 deletions packages/renderers/renderer-solid/client.js
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
);
};