7
7
8
8
import {
9
9
enableIsInputPending ,
10
- requestIdleCallbackBeforeFirstFrame as requestIdleCallbackBeforeFirstFrameFlag ,
11
- requestTimerEventBeforeFirstFrame ,
12
10
enableMessageLoopImplementation ,
13
11
} from '../SchedulerFeatureFlags' ;
14
12
87
85
const clearTimeout = window . clearTimeout ;
88
86
const requestAnimationFrame = window . requestAnimationFrame ;
89
87
const cancelAnimationFrame = window . cancelAnimationFrame ;
90
- const requestIdleCallback = window . requestIdleCallback ;
91
88
92
89
if ( typeof console !== 'undefined' ) {
93
90
// TODO: Remove fb.me link
@@ -107,11 +104,6 @@ if (
107
104
}
108
105
}
109
106
110
- const requestIdleCallbackBeforeFirstFrame =
111
- requestIdleCallbackBeforeFirstFrameFlag &&
112
- typeof requestIdleCallback === 'function' &&
113
- typeof cancelIdleCallback === 'function' ;
114
-
115
107
if (
116
108
typeof performance === 'object' &&
117
109
typeof performance . now === 'function'
@@ -359,50 +351,8 @@ if (
359
351
// Start a rAF loop.
360
352
isRAFLoopRunning = true ;
361
353
requestAnimationFrame ( rAFTime => {
362
- if ( requestIdleCallbackBeforeFirstFrame ) {
363
- cancelIdleCallback ( idleCallbackID ) ;
364
- }
365
- if ( requestTimerEventBeforeFirstFrame ) {
366
- clearTimeout ( idleTimeoutID ) ;
367
- }
368
354
onAnimationFrame ( rAFTime ) ;
369
355
} ) ;
370
-
371
- // If we just missed the last vsync, the next rAF might not happen for
372
- // another frame. To claim as much idle time as possible, post a
373
- // callback with `requestIdleCallback`, which should fire if there's
374
- // idle time left in the frame.
375
- //
376
- // This should only be an issue for the first rAF in the loop;
377
- // subsequent rAFs are scheduled at the beginning of the
378
- // preceding frame.
379
- let idleCallbackID ;
380
- if ( requestIdleCallbackBeforeFirstFrame ) {
381
- idleCallbackID = requestIdleCallback (
382
- function onIdleCallbackBeforeFirstFrame ( ) {
383
- if ( requestTimerEventBeforeFirstFrame ) {
384
- clearTimeout ( idleTimeoutID ) ;
385
- }
386
- frameDeadline = getCurrentTime ( ) + frameLength ;
387
- performWorkUntilDeadline ( ) ;
388
- } ,
389
- ) ;
390
- }
391
- // Alternate strategy to address the same problem. Scheduler a timer
392
- // with no delay. If this fires before the rAF, that likely indicates
393
- // that there's idle time before the next vsync. This isn't always the
394
- // case, but we'll be aggressive and assume it is, as a trade off to
395
- // prevent idle periods.
396
- let idleTimeoutID ;
397
- if ( requestTimerEventBeforeFirstFrame ) {
398
- idleTimeoutID = setTimeout ( function onTimerEventBeforeFirstFrame ( ) {
399
- if ( requestIdleCallbackBeforeFirstFrame ) {
400
- cancelIdleCallback ( idleCallbackID ) ;
401
- }
402
- frameDeadline = getCurrentTime ( ) + frameLength ;
403
- performWorkUntilDeadline ( ) ;
404
- } , 0 ) ;
405
- }
406
356
}
407
357
}
408
358
} ;
0 commit comments