From 99ee6c3979e15cd3660c637780f96bd9f0b6d331 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Sun, 4 Aug 2024 10:06:55 +0800 Subject: [PATCH] Don't reuse var for both timeout and interval --- src/components/background-service.jsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/background-service.jsx b/src/components/background-service.jsx index 15647fe1..bcadd2a4 100644 --- a/src/components/background-service.jsx +++ b/src/components/background-service.jsx @@ -46,6 +46,7 @@ export default memo(function BackgroundService({ isLoggedIn }) { useEffect(() => { let sub; + let streamTimeout; let pollNotifications; if (isLoggedIn && visible) { const { masto, streaming, instance } = api(); @@ -56,7 +57,7 @@ export default memo(function BackgroundService({ isLoggedIn }) { let hasStreaming = false; // 2. Start streaming if (streaming) { - pollNotifications = setTimeout(() => { + streamTimeout = setTimeout(() => { (async () => { try { hasStreaming = true; @@ -94,7 +95,7 @@ export default memo(function BackgroundService({ isLoggedIn }) { return () => { sub?.unsubscribe?.(); sub = null; - clearTimeout(pollNotifications); + clearTimeout(streamTimeout); clearInterval(pollNotifications); }; }, [visible, isLoggedIn]);