diff options
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 }); }; |