Skip to content

Commit 3907062

Browse files
Fix issue #4693 by
reading window.requestAnimationFrame within the autoBatchEnhancer function instead of in the top-level module scope. This ensures that we use the fake version of requestAnimationFrame if jest is using fake timers.
1 parent a0858eb commit 3907062

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

packages/toolkit/src/autoBatchEnhancer.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ const createQueueWithTimer = (timeout: number) => {
1515
}
1616
}
1717

18-
// requestAnimationFrame won't exist in SSR environments.
19-
// Fall back to a vague approximation just to keep from erroring.
20-
const rAF =
21-
typeof window !== 'undefined' && window.requestAnimationFrame
22-
? window.requestAnimationFrame
23-
: createQueueWithTimer(10)
24-
2518
export type AutoBatchOptions =
2619
| { type: 'tick' }
2720
| { type: 'timer'; timeout: number }
@@ -66,7 +59,10 @@ export const autoBatchEnhancer =
6659
options.type === 'tick'
6760
? queueMicrotask
6861
: options.type === 'raf'
69-
? rAF
62+
? // requestAnimationFrame won't exist in SSR environments. Fall back to a vague approximation just to keep from erroring.
63+
typeof window !== 'undefined' && window.requestAnimationFrame
64+
? window.requestAnimationFrame
65+
: createQueueWithTimer(10)
7066
: options.type === 'callback'
7167
? options.queueNotification
7268
: createQueueWithTimer(options.timeout)

0 commit comments

Comments
 (0)