Skip to content

Commit

Permalink
Merge pull request #746 from MuckRock/allanlasser/issue742
Browse files Browse the repository at this point in the history
Removes Portal from DOM when destroying
  • Loading branch information
allanlasser authored Oct 1, 2024
2 parents 45c2bcc + 7b5889a commit 8e79df7
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/lib/components/layouts/Portal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- Source: https://github.com/sveltejs/svelte/issues/3088#issuecomment-1065827485 -->

<script lang="ts">
import { onMount, onDestroy } from 'svelte';
import { onMount, onDestroy } from "svelte";
export let target: HTMLElement | null | undefined = globalThis.document?.body;
Expand All @@ -12,18 +12,15 @@
if (target) {
target.appendChild(ref);
}
})
});
// this block is almost needless/useless (if not totally) as, on destroy, the ref will no longer exist/be in the DOM anyways
onDestroy(() => {
setTimeout(() => {
if (ref?.parentNode) {
ref.parentNode?.removeChild(ref);
}
})
})
if (target) {
target.removeChild(ref);
}
});
</script>

<div bind:this={ref} style="display:contents;">
<slot />
</div>
</div>

0 comments on commit 8e79df7

Please sign in to comment.