diff options
author | 2023-02-15 22:28:59 +0800 | |
---|---|---|
committer | 2023-02-15 22:28:59 +0800 | |
commit | 5c7c7e463dbffc9a573e3fec80a4daaf4621cd83 (patch) | |
tree | 994dac0b5972653695e22856bb8b570097e75889 /packages/integrations/svelte | |
parent | 4b89c2b553aa93c53d6262f473f0fe793e034614 (diff) | |
download | astro-5c7c7e463dbffc9a573e3fec80a4daaf4621cd83.tar.gz astro-5c7c7e463dbffc9a573e3fec80a4daaf4621cd83.tar.zst astro-5c7c7e463dbffc9a573e3fec80a4daaf4621cd83.zip |
Fix unmount Svelte slots (#6250)
Diffstat (limited to 'packages/integrations/svelte')
-rw-r--r-- | packages/integrations/svelte/client.js | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/packages/integrations/svelte/client.js b/packages/integrations/svelte/client.js index 406500374..658ddb02f 100644 --- a/packages/integrations/svelte/client.js +++ b/packages/integrations/svelte/client.js @@ -23,10 +23,12 @@ export default (target) => { }; function createSlotDefinition(key, children) { + let parent; return [ () => ({ // mount m(target) { + parent = target; target.insertAdjacentHTML( 'beforeend', `<astro-slot${key === 'default' ? '' : ` name="${key}"`}>${children}</astro-slot>` @@ -37,7 +39,13 @@ function createSlotDefinition(key, children) { // hydrate l: noop, // destroy - d: noop, + d() { + if (!parent) return; + const slot = parent.querySelector( + `astro-slot${key === 'default' ? ':not([name])' : `[name="${key}"]`}` + ); + if (slot) slot.remove(); + }, }), noop, noop, |