From 3cc39e61c0c7fb86f2aa09fab71ed301d70e5bba Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 6 Jul 2026 22:13:47 +0200 Subject: [PATCH] fix: timeout leak in useIdle (#12908) --- app/hooks/useIdle.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/hooks/useIdle.ts b/app/hooks/useIdle.ts index d0088091c9..f7bb071fc4 100644 --- a/app/hooks/useIdle.ts +++ b/app/hooks/useIdle.ts @@ -53,7 +53,16 @@ export default function useIdle( events.forEach((eventName) => window.addEventListener(eventName, handleUserActivityEvent) ); + + // Start the countdown immediately, otherwise the user is never considered + // idle unless activity occurs after mount. + onActivity(); + return () => { + handleUserActivityEvent.cancel(); + if (timeout.current) { + clearTimeout(timeout.current); + } events.forEach((eventName) => window.removeEventListener(eventName, handleUserActivityEvent) );