File tree Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -29,18 +29,25 @@ const queueMicrotaskShim =
29
29
} , 0 )
30
30
)
31
31
32
- export type AutoBatchOptions =
33
- | { type : 'tick' }
34
- | { type : 'timer' ; timeout : number }
35
- | { type : 'raf' }
36
- | { type : 'callback' ; queueNotification : ( notify : ( ) => void ) => void }
37
-
38
32
const createQueueWithTimer = ( timeout : number ) => {
39
33
return ( notify : ( ) => void ) => {
40
34
setTimeout ( notify , timeout )
41
35
}
42
36
}
43
37
38
+ // requestAnimationFrame won't exist in SSR environments.
39
+ // Fall back to a vague approximation just to keep from erroring.
40
+ const rAF =
41
+ typeof window !== 'undefined' && window . requestAnimationFrame
42
+ ? window . requestAnimationFrame
43
+ : createQueueWithTimer ( 10 )
44
+
45
+ export type AutoBatchOptions =
46
+ | { type : 'tick' }
47
+ | { type : 'timer' ; timeout : number }
48
+ | { type : 'raf' }
49
+ | { type : 'callback' ; queueNotification : ( notify : ( ) => void ) => void }
50
+
44
51
/**
45
52
* A Redux store enhancer that watches for "low-priority" actions, and delays
46
53
* notifying subscribers until either the queued callback executes or the
@@ -79,7 +86,7 @@ export const autoBatchEnhancer =
79
86
options . type === 'tick'
80
87
? queueMicrotaskShim
81
88
: options . type === 'raf'
82
- ? requestAnimationFrame
89
+ ? rAF
83
90
: options . type === 'callback'
84
91
? options . queueNotification
85
92
: createQueueWithTimer ( options . timeout )
You can’t perform that action at this time.
0 commit comments