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.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.js')
-rw-r--r-- | packages/integrations/svelte/client.js | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/packages/integrations/svelte/client.js b/packages/integrations/svelte/client.js index 005bbe9da..288c7a661 100644 --- a/packages/integrations/svelte/client.js +++ b/packages/integrations/svelte/client.js @@ -3,6 +3,8 @@ const noop = () => {}; let originalConsoleWarning; let consoleFilterRefs = 0; +const existingApplications = new WeakMap(); + export default (element) => { return (Component, props, slotted, { client }) => { if (!element.hasAttribute('ssr')) return; @@ -14,18 +16,23 @@ export default (element) => { try { if (import.meta.env.DEV) useConsoleFilter(); - const component = new Component({ - target: element, - props: { - ...props, - $$slots: slots, - $$scope: { ctx: [] }, - }, - hydrate: client !== 'only', - $$inline: true, - }); + if (existingApplications.has(element)) { + existingApplications.get(element).$set({ ...props, $$slots: slots, $$scope: { ctx: [] } }); + } else { + const component = new Component({ + target: element, + props: { + ...props, + $$slots: slots, + $$scope: { ctx: [] }, + }, + hydrate: client !== 'only', + $$inline: true, + }); + existingApplications.set(element, component); - element.addEventListener('astro:unmount', () => component.$destroy(), { once: true }); + element.addEventListener('astro:unmount', () => component.$destroy(), { once: true }); + } } finally { if (import.meta.env.DEV) finishUsingConsoleFilter(); } |