aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-04-18 09:14:37 +0000
committerFuwn <[email protected]>2026-04-18 09:14:37 +0000
commit71cb450cbdd92bbb1aaedc43e9d4eae1e5206234 (patch)
tree18635039a1f637113dd913fae8e985b0afbb896a
parentfix(notification): clear auto-dismiss timer on component destroy (diff)
downloaddue.moe-71cb450cbdd92bbb1aaedc43e9d4eae1e5206234.tar.xz
due.moe-71cb450cbdd92bbb1aaedc43e9d4eae1e5206234.zip
fix(tooltip): remove body-appended tooltip node on destroy
LinkedTooltip appends its tooltip div directly to document.body in createTooltip and only removes it from hideTooltip. If the component was destroyed while the tooltip was visible (e.g. parent navigated mid-hover), the div leaked and stayed in the DOM forever. Add an onDestroy handler that clears the pending hide/debounce timers and, if the tooltip div is still parented to document.body, removes it. Guarding on parentNode avoids double-removal when hideTooltip has already run.
-rw-r--r--src/lib/Tooltip/LinkedTooltip.svelte12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/lib/Tooltip/LinkedTooltip.svelte b/src/lib/Tooltip/LinkedTooltip.svelte
index 82147536..b3fc6ae2 100644
--- a/src/lib/Tooltip/LinkedTooltip.svelte
+++ b/src/lib/Tooltip/LinkedTooltip.svelte
@@ -1,6 +1,7 @@
<script lang="ts">
import tooltipPosition from "$stores/tooltipPosition";
import { fade } from "svelte/transition";
+import { onDestroy } from "svelte";
export let id: string | undefined = undefined;
export let pin: string | undefined = undefined;
@@ -20,6 +21,17 @@ let hideTimeout: number | null = null;
let debounceTimer: number | null = null;
let opacity = 0;
+onDestroy(() => {
+ if (hideTimeout !== null) clearTimeout(hideTimeout);
+
+ if (debounceTimer !== null) clearTimeout(debounceTimer);
+
+ if (tooltipDiv && tooltipDiv.parentNode === document.body) {
+ document.body.removeChild(tooltipDiv);
+ tooltipDiv = null;
+ }
+});
+
const createTooltip = () => {
if (!tooltipDiv) {
tooltipDiv = document.createElement("div");