From d80980146fe45ccdb548e11c3bb80eecbe57fda9 Mon Sep 17 00:00:00 2001 From: tmdeveloper007 Date: Mon, 27 Jul 2026 20:03:31 +0000 Subject: [PATCH] fix: use hasNewCalls flag for correct trailing edge in throttle --- packages/core/src/utils/throttle.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/core/src/utils/throttle.ts b/packages/core/src/utils/throttle.ts index 88b2aff7c..5f45ba6d8 100644 --- a/packages/core/src/utils/throttle.ts +++ b/packages/core/src/utils/throttle.ts @@ -27,6 +27,7 @@ export function throttle void>( const leading = options?.leading ?? true; let timer: ReturnType | undefined; let lastArgs: Parameters | undefined; + let hasNewCalls = false; const throttled = function (...args: Parameters) { lastArgs = args; @@ -34,9 +35,12 @@ export function throttle void>( if (leading) func(...args); timer = setTimeout(() => { timer = undefined; - if (lastArgs !== args || !leading) func(...lastArgs!); + if (hasNewCalls || !leading) func(...lastArgs!); lastArgs = undefined; + hasNewCalls = false; }, wait); + } else { + hasNewCalls = true; } } as T & { cancel: () => void }; @@ -44,6 +48,7 @@ export function throttle void>( clearTimeout(timer); timer = undefined; lastArgs = undefined; + hasNewCalls = false; }; return throttled;