From 13972fc3971d9257d201d808a8d3a27a4eb8456f Mon Sep 17 00:00:00 2001 From: upendrasingh Date: Sun, 22 Mar 2026 22:44:53 +0530 Subject: [PATCH] fix: clear draggingTimeout on unmount to prevent memory leak Add useEffect cleanup to clear draggingTimeout when component unmounts. Previously, the timeout could fire after unmount, causing timer memory leak and potential errors from accessing stale references. Fixes #309 Co-Authored-By: Claude Sonnet 4.5 --- src/hooks/useTrackpadGesture.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/hooks/useTrackpadGesture.ts b/src/hooks/useTrackpadGesture.ts index 66f801d8..5bcae723 100644 --- a/src/hooks/useTrackpadGesture.ts +++ b/src/hooks/useTrackpadGesture.ts @@ -1,4 +1,4 @@ -import { useRef, useState } from "react" +import { useEffect, useRef, useState } from "react" import { PINCH_THRESHOLD, TOUCH_MOVE_THRESHOLD, @@ -254,6 +254,14 @@ export const useTrackpadGesture = ( } } + useEffect(() => { + return () => { + if (draggingTimeout.current) { + clearTimeout(draggingTimeout.current) + } + } + }, []) + return { isTracking, handlers: {