summaryrefslogtreecommitdiff
path: root/packages/integrations/svelte/client.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/integrations/svelte/client.js')
-rw-r--r--packages/integrations/svelte/client.js10
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,