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) );