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;