From 7a612e60cf83dd6dbec96be906b6687716f93400 Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Wed, 25 Dec 2019 06:20:38 -0800 Subject: [PATCH] feat(toast-notification): clear timeout when destroyed --- src/components/Notification/ToastNotification.svelte | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/Notification/ToastNotification.svelte b/src/components/Notification/ToastNotification.svelte index 11cab4f3..2bd01c7f 100644 --- a/src/components/Notification/ToastNotification.svelte +++ b/src/components/Notification/ToastNotification.svelte @@ -21,14 +21,20 @@ const dispatch = createEventDispatcher(); + let timeoutId = undefined; let open = true; onMount(() => { if (timeout) { - window.setTimeout(() => { + timeoutId = window.setTimeout(() => { open = false; }, timeout); } + + return () => { + window.clearTimeout(timeoutId); + timeoutId = undefined; + }; }); $: if (!open) {