mirror of
https://github.com/outline/outline.git
synced 2026-08-03 13:27:25 +03:00
fix: timeout leak in useIdle (#12908)
This commit is contained in:
@@ -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)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user