diff options
author | 2025-03-20 11:43:04 +0000 | |
---|---|---|
committer | 2025-03-20 11:43:04 +0000 | |
commit | ecadb6b02e942feccf584547fe9c14d3d1e21ba6 (patch) | |
tree | 100d7bfc923e53b726c20daf050fd9720a2c306b /packages/integrations/preact/src | |
parent | 62595a00c6d8a24f587abce6a9c7cff6e9f1da68 (diff) | |
download | astro-ecadb6b02e942feccf584547fe9c14d3d1e21ba6.tar.gz astro-ecadb6b02e942feccf584547fe9c14d3d1e21ba6.tar.zst astro-ecadb6b02e942feccf584547fe9c14d3d1e21ba6.zip |
fix(preact,svelte): empty target container before rendering `client:only` island (#13470)
* fix(preact,svelte): empty target container before rendering `client:only` island
* Remove log
Diffstat (limited to 'packages/integrations/preact/src')
-rw-r--r-- | packages/integrations/preact/src/client.ts | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/packages/integrations/preact/src/client.ts b/packages/integrations/preact/src/client.ts index 32fdc9888..40475acc8 100644 --- a/packages/integrations/preact/src/client.ts +++ b/packages/integrations/preact/src/client.ts @@ -49,13 +49,19 @@ export default (element: HTMLElement) => } } - const bootstrap = client !== 'only' ? hydrate : render; - - bootstrap( - h(Component, props, children != null ? h(StaticHtml, { value: children }) : children), - element, + const child = h( + Component, + props, + children != null ? h(StaticHtml, { value: children }) : children, ); + if (client === 'only') { + element.innerHTML = ''; + render(child, element); + } else { + hydrate(child, element); + } + // Preact has no "unmount" option, but you can use `render(null, element)` element.addEventListener('astro:unmount', () => render(null, element), { once: true }); }; |