From fa592f882a6793fd81cc374fd0245c9f5850d9dd Mon Sep 17 00:00:00 2001 From: Jon Koops Date: Fri, 28 Jul 2023 11:41:40 +0200 Subject: [PATCH] Ensure mounted state in `useSetTimeout()` remains consistent (#22025) --- js/apps/admin-ui/src/utils/useSetTimeout.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/js/apps/admin-ui/src/utils/useSetTimeout.ts b/js/apps/admin-ui/src/utils/useSetTimeout.ts index 0c605fd8ab..502075f0de 100644 --- a/js/apps/admin-ui/src/utils/useSetTimeout.ts +++ b/js/apps/admin-ui/src/utils/useSetTimeout.ts @@ -4,13 +4,14 @@ export default function useSetTimeout() { const didUnmountRef = useRef(false); const { current: scheduledTimers } = useRef(new Set()); - useEffect( - () => () => { + useEffect(() => { + didUnmountRef.current = false; + + return () => { didUnmountRef.current = true; clearAll(); - }, - [], - ); + }; + }, []); function clearAll() { scheduledTimers.forEach((timer) => clearTimeout(timer));