77
88import {
99 enableIsInputPending ,
10- requestIdleCallbackBeforeFirstFrame as requestIdleCallbackBeforeFirstFrameFlag ,
11- requestTimerEventBeforeFirstFrame ,
1210 enableMessageLoopImplementation ,
1311} from '../SchedulerFeatureFlags' ;
1412
8785 const clearTimeout = window . clearTimeout ;
8886 const requestAnimationFrame = window . requestAnimationFrame ;
8987 const cancelAnimationFrame = window . cancelAnimationFrame ;
90- const requestIdleCallback = window . requestIdleCallback ;
9188
9289 if ( typeof console !== 'undefined' ) {
9390 // TODO: Remove fb.me link
@@ -107,11 +104,6 @@ if (
107104 }
108105 }
109106
110- const requestIdleCallbackBeforeFirstFrame =
111- requestIdleCallbackBeforeFirstFrameFlag &&
112- typeof requestIdleCallback === 'function' &&
113- typeof cancelIdleCallback === 'function' ;
114-
115107 if (
116108 typeof performance === 'object' &&
117109 typeof performance . now === 'function'
@@ -359,50 +351,8 @@ if (
359351 // Start a rAF loop.
360352 isRAFLoopRunning = true ;
361353 requestAnimationFrame ( rAFTime => {
362- if ( requestIdleCallbackBeforeFirstFrame ) {
363- cancelIdleCallback ( idleCallbackID ) ;
364- }
365- if ( requestTimerEventBeforeFirstFrame ) {
366- clearTimeout ( idleTimeoutID ) ;
367- }
368354 onAnimationFrame ( rAFTime ) ;
369355 } ) ;
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- }
406356 }
407357 }
408358 } ;
0 commit comments