diff options
author | 2023-08-29 09:30:11 -0500 | |
---|---|---|
committer | 2023-08-29 09:30:11 -0500 | |
commit | 1f58a7a1bea6888868b689dac94801d554319b02 (patch) | |
tree | d211fa64f18e32ca0798e1ca93b96c2477eea322 /packages/integrations/react/client-v17.js | |
parent | 9e021a91c57d10809f588dd47968fc0e7f8b4d5c (diff) | |
download | astro-1f58a7a1bea6888868b689dac94801d554319b02.tar.gz astro-1f58a7a1bea6888868b689dac94801d554319b02.tar.zst astro-1f58a7a1bea6888868b689dac94801d554319b02.zip |
Unmount framework components when islands are destroyed (#8264)
* fix(view-transitions): update persistence logic for improved unmount behavior
* feat(astro): add `astro:unmount` event
* feat(vue): automatically unmount islands
* feat(react): automatically unmount islands
* feat(react): automatically unmount islands
* feat(solid): automatically dispose of islands
* feat(svelte): automatically destroy of islands
* feat(svelte): automatically destroy of islands
* feat(solid): automatically dispose of islands
* feat(preact): automatically unmount islands
* chore: update changeset
* fix: rebase issue
* chore: add clarifying comment
* chore: remove duplicate changeset
* chore: add changeset
Diffstat (limited to 'packages/integrations/react/client-v17.js')
-rw-r--r-- | packages/integrations/react/client-v17.js | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/packages/integrations/react/client-v17.js b/packages/integrations/react/client-v17.js index 443109603..70bddc353 100644 --- a/packages/integrations/react/client-v17.js +++ b/packages/integrations/react/client-v17.js @@ -1,5 +1,5 @@ import { createElement } from 'react'; -import { render, hydrate } from 'react-dom'; +import { render, hydrate, unmountComponentAtNode } from 'react-dom'; import StaticHtml from './static-html.js'; export default (element) => @@ -12,8 +12,9 @@ export default (element) => props, children != null ? createElement(StaticHtml, { value: children }) : children ); - if (client === 'only') { - return render(componentEl, element); - } - return hydrate(componentEl, element); + + const isHydrate = client !== 'only'; + const bootstrap = isHydrate ? hydrate : render; + bootstrap(componentEl, element); + element.addEventListener('astro:unmount', () => unmountComponentAtNode(element), { once: true }); }; |