From 3f49aa97ab8fb4bffe50da993cae0f0027c7692d Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Thu, 7 Sep 2023 09:49:59 -0500 Subject: [PATCH] fix(svelte): unmount islands properly on navigation (#8448) --- .changeset/sweet-sheep-sell.md | 5 +++++ packages/integrations/svelte/client.js | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 .changeset/sweet-sheep-sell.md diff --git a/.changeset/sweet-sheep-sell.md b/.changeset/sweet-sheep-sell.md new file mode 100644 index 000000000..986a60478 --- /dev/null +++ b/.changeset/sweet-sheep-sell.md @@ -0,0 +1,5 @@ +--- +'@astrojs/svelte': patch +--- + +Fix potential memory leak when component is unmounted diff --git a/packages/integrations/svelte/client.js b/packages/integrations/svelte/client.js index 73cc305c1..9e3df4019 100644 --- a/packages/integrations/svelte/client.js +++ b/packages/integrations/svelte/client.js @@ -3,9 +3,9 @@ const noop = () => {}; let originalConsoleWarning; let consoleFilterRefs = 0; -export default (target) => { +export default (element) => { return (Component, props, slotted, { client }) => { - if (!target.hasAttribute('ssr')) return; + if (!element.hasAttribute('ssr')) return; const slots = {}; for (const [key, value] of Object.entries(slotted)) { slots[key] = createSlotDefinition(key, value); @@ -15,7 +15,7 @@ export default (target) => { if (import.meta.env.DEV) useConsoleFilter(); const component = new Component({ - target, + target: element, props: { ...props, $$slots: slots,