diff options
author | 2024-09-18 16:42:44 +0100 | |
---|---|---|
committer | 2024-09-18 16:43:14 +0100 | |
commit | b0827022afa52a13d49c37c6c549212aecd32cc5 (patch) | |
tree | 41e34f22f8fa388ca78e62a2ee802367d7e3cf42 /packages/integrations/svelte/client-v5.js | |
parent | 837ee3a4aa6b33362bd680d4a7fc786ed8639444 (diff) | |
parent | 8d4eb95086ae79339764d02215f84f4f21b96edc (diff) | |
download | astro-b0827022afa52a13d49c37c6c549212aecd32cc5.tar.gz astro-b0827022afa52a13d49c37c6c549212aecd32cc5.tar.zst astro-b0827022afa52a13d49c37c6c549212aecd32cc5.zip |
Merge branch 'main' into next
Diffstat (limited to 'packages/integrations/svelte/client-v5.js')
-rw-r--r-- | packages/integrations/svelte/client-v5.js | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/packages/integrations/svelte/client-v5.js b/packages/integrations/svelte/client-v5.js index fda68ee54..78bab3ea3 100644 --- a/packages/integrations/svelte/client-v5.js +++ b/packages/integrations/svelte/client-v5.js @@ -1,5 +1,7 @@ import { createRawSnippet, hydrate, mount, unmount } from 'svelte'; +const existingApplications = new WeakMap(); + export default (element) => { return async (Component, props, slotted, { client }) => { if (!element.hasAttribute('ssr')) return; @@ -21,15 +23,23 @@ export default (element) => { } const bootstrap = client !== 'only' ? hydrate : mount; - - const component = bootstrap(Component, { - target: element, - props: { + if (existingApplications.has(element)) { + existingApplications.get(element).$set({ ...props, children, $$slots, - }, - }); + }); + } else { + const component = bootstrap(Component, { + target: element, + props: { + ...props, + children, + $$slots, + }, + }); + existingApplications.set(element, component); + } element.addEventListener('astro:unmount', () => unmount(component), { once: true }); }; |