Skip to content

Commit f4bb712

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 24286f1 commit f4bb712

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

packages/toolkit/src/autoBatchEnhancer.ts

Lines changed: 7 additions & 7 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 }
@@ -62,6 +55,13 @@ export const autoBatchEnhancer =
6255

6356
const listeners = new Set<() => void>()
6457

58+
// requestAnimationFrame won't exist in SSR environments.
59+
// Fall back to a vague approximation just to keep from erroring.
60+
const rAF =
61+
typeof window !== 'undefined' && window.requestAnimationFrame
62+
? window.requestAnimationFrame
63+
: createQueueWithTimer(10)
64+
6565
const queueCallback =
6666
options.type === 'tick'
6767
? queueMicrotask

0 commit comments

Comments
 (0)