Skip to content

Commit aacdf2b

Browse files
billyvgmydea
andauthored
fix(replay): Fix debounce when maxWait == wait (#7208)
Co-authored-by: Francesco Novy <[email protected]>
1 parent 8305b94 commit aacdf2b

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

packages/replay/src/util/debounce.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function debounce(func: CallbackFunction, wait: number, options?: Debounc
5757
}
5858
timerId = setTimeout(invokeFunc, wait);
5959

60-
if (maxWait && maxTimerId === undefined && maxWait !== wait) {
60+
if (maxWait && maxTimerId === undefined) {
6161
maxTimerId = setTimeout(invokeFunc, maxWait);
6262
}
6363

packages/replay/test/unit/util/debounce.test.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,27 @@ describe('Unit | util | debounce', () => {
246246
const debouncedCallback = debounce(callback, 100, { maxWait: 100 });
247247

248248
debouncedCallback();
249-
jest.advanceTimersByTime(100);
249+
jest.advanceTimersByTime(25);
250+
debouncedCallback();
251+
jest.advanceTimersByTime(25);
252+
debouncedCallback();
253+
jest.advanceTimersByTime(25);
254+
debouncedCallback();
255+
jest.advanceTimersByTime(25);
250256

251257
expect(callback).toHaveBeenCalledTimes(1);
252258

253259
const retval = debouncedCallback();
254260
expect(retval).toBe('foo');
255261

256-
jest.advanceTimersByTime(100);
262+
jest.advanceTimersByTime(25);
263+
debouncedCallback();
264+
jest.advanceTimersByTime(25);
265+
debouncedCallback();
266+
jest.advanceTimersByTime(25);
267+
debouncedCallback();
268+
jest.advanceTimersByTime(25);
269+
257270
expect(callback).toHaveBeenCalledTimes(2);
258271
});
259272
});

0 commit comments

Comments
 (0)