diff --git a/packages/toolkit/src/autoBatchEnhancer.ts b/packages/toolkit/src/autoBatchEnhancer.ts index 7479d49ef5..06dbd23965 100644 --- a/packages/toolkit/src/autoBatchEnhancer.ts +++ b/packages/toolkit/src/autoBatchEnhancer.ts @@ -15,13 +15,6 @@ const createQueueWithTimer = (timeout: number) => { } } -// requestAnimationFrame won't exist in SSR environments. -// Fall back to a vague approximation just to keep from erroring. -const rAF = - typeof window !== 'undefined' && window.requestAnimationFrame - ? window.requestAnimationFrame - : createQueueWithTimer(10) - export type AutoBatchOptions = | { type: 'tick' } | { type: 'timer'; timeout: number } @@ -66,7 +59,8 @@ export const autoBatchEnhancer = options.type === 'tick' ? queueMicrotask : options.type === 'raf' - ? rAF + ? // requestAnimationFrame won't exist in SSR environments. Fall back to a vague approximation just to keep from erroring. + window?.requestAnimationFrame ?? createQueueWithTimer(10) : options.type === 'callback' ? options.queueNotification : createQueueWithTimer(options.timeout)