diff options
author | 2022-05-31 11:29:36 -0500 | |
---|---|---|
committer | 2022-05-31 11:29:36 -0500 | |
commit | e9a77d861907adccfa75811f9aaa555f186d78f8 (patch) | |
tree | 1c77ae43165a7f529ea5762811798c3873f1776c /packages/integrations/solid/client.js | |
parent | 40614597ccef567afab31621834037b0a77ed317 (diff) | |
download | astro-e9a77d861907adccfa75811f9aaa555f186d78f8.tar.gz astro-e9a77d861907adccfa75811f9aaa555f186d78f8.tar.zst astro-e9a77d861907adccfa75811f9aaa555f186d78f8.zip |
Improve nested and `client:only` hydration (#3455)
* wip: fix nested islands
* fix: improve hydration for dynamic content
* chore: fix bundle-size script for new files
* chore: allow-list client:* directive files
* fix(#3362): fix client:only behavior for React, Vue, Solid
* test: add client-only e2e test
* chore: update lockfile
* test: fix e2e tests
* test: add framework nesting e2e tests
* Update packages/astro/src/runtime/client/events.ts
Co-authored-by: Matthew Phillips <matthew@skypack.dev>
* chore: add changeset
* fix(preact): ignore hydrate roots
* chore: remove `ssr` check in integrations
* Revert "chore: remove `ssr` check in integrations"
This reverts commit ba27eaae5514701f4b7bb6259f682fe82821a23d.
* chore: add changeset
Co-authored-by: Matthew Phillips <matthew@skypack.dev>
Diffstat (limited to 'packages/integrations/solid/client.js')
-rw-r--r-- | packages/integrations/solid/client.js | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/packages/integrations/solid/client.js b/packages/integrations/solid/client.js index d31c5cecd..005f3c980 100644 --- a/packages/integrations/solid/client.js +++ b/packages/integrations/solid/client.js @@ -1,21 +1,27 @@ import { sharedConfig } from 'solid-js'; -import { hydrate, createComponent } from 'solid-js/web'; +import { hydrate, render, createComponent } from 'solid-js/web'; -export default (element) => (Component, props, childHTML) => { +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; + + const fn = client === 'only' ? render : hydrate; + // Perform actual hydration let children; - hydrate( + fn( () => createComponent(Component, { ...props, get children() { if (childHTML != null) { // hydrating - if (sharedConfig.context) children = element.querySelector('astro-fragment'); + if (sharedConfig.context) { + children = element.querySelector('astro-fragment'); + } if (children == null) { children = document.createElement('astro-fragment'); |