From 21e90a0c7d6efce32e2fa5ef4152082ef8e7cae9 Mon Sep 17 00:00:00 2001 From: Yanzhen Yu Date: Wed, 1 Apr 2026 12:00:00 +0800 Subject: [PATCH] hotfix throttle function args --- package.json | 2 +- src/utils.ts | 3 ++- typings/utils.d.ts | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 8c07f542..5c6c3a7f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rrweb", - "version": "0.7.20", + "version": "0.7.21", "description": "record and replay the web", "scripts": { "test": "npm run bundle:browser && cross-env TS_NODE_CACHE=false TS_NODE_FILES=true mocha -r ts-node/register test/**/*.test.ts", diff --git a/src/utils.ts b/src/utils.ts index fa96524e..2ee32c2f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -53,13 +53,14 @@ export function throttle( let timeout: number | null = null; let previous = 0; // tslint:disable-next-line: only-arrow-functions - return function(args: T) { + return function(arg: T) { let now = Date.now(); if (!previous && options.leading === false) { previous = now; } let remaining = wait - (now - previous); let context = this; + let args = arguments; if (remaining <= 0 || remaining > wait) { if (timeout) { window.clearTimeout(timeout); diff --git a/typings/utils.d.ts b/typings/utils.d.ts index 4d176dc2..732c10a9 100644 --- a/typings/utils.d.ts +++ b/typings/utils.d.ts @@ -2,7 +2,7 @@ import { Mirror, throttleOptions, listenerHandler, hookResetter, blockClass } fr import { INode } from 'rrweb-snapshot'; export declare function on(type: string, fn: EventListenerOrEventListenerObject, target?: Document | Window): listenerHandler; export declare const mirror: Mirror; -export declare function throttle(func: (arg: T) => void, wait: number, options?: throttleOptions): (args: T) => void; +export declare function throttle(func: (arg: T) => void, wait: number, options?: throttleOptions): () => void; export declare function hookSetter(target: T, key: string | number | symbol, d: PropertyDescriptor, isRevoked?: boolean): hookResetter; export declare function getWindowHeight(): number; export declare function getWindowWidth(): number;