File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -183,7 +183,7 @@ describe('SchedulerBrowser', () => {
183183 it ( 'task with continuation' , ( ) => {
184184 scheduleCallback ( NormalPriority , ( ) => {
185185 runtime . log ( 'Task' ) ;
186- // Request paint so that we yield at the end of the frame interval
186+ // Request paint so that we yield immediately
187187 requestPaint ( ) ;
188188 while ( ! Scheduler . unstable_shouldYield ( ) ) {
189189 runtime . advanceTime ( 1 ) ;
@@ -199,7 +199,7 @@ describe('SchedulerBrowser', () => {
199199 runtime . assertLog ( [
200200 'Message Event' ,
201201 'Task' ,
202- gate ( flags => ( flags . www ? 'Yield at 10ms' : 'Yield at 5ms' ) ) ,
202+ 'Yield at 0ms' ,
203203 'Post Message' ,
204204 ] ) ;
205205
Original file line number Diff line number Diff line change @@ -93,6 +93,8 @@ var isPerformingWork = false;
9393var isHostCallbackScheduled = false;
9494var isHostTimeoutScheduled = false;
9595
96+ var needsPaint = false;
97+
9698// Capture local references to native APIs, in case a polyfill overrides them.
9799const localSetTimeout = typeof setTimeout === 'function' ? setTimeout : null;
98100const localClearTimeout =
@@ -456,6 +458,10 @@ let frameInterval = frameYieldMs;
456458let startTime = - 1 ;
457459
458460function shouldYieldToHost ( ) : boolean {
461+ if ( needsPaint ) {
462+ // Yield now.
463+ return true ;
464+ }
459465 const timeElapsed = getCurrentTime ( ) - startTime ;
460466 if ( timeElapsed < frameInterval ) {
461467 // The main thread has only been blocked for a really short amount of time;
@@ -466,7 +472,9 @@ function shouldYieldToHost(): boolean {
466472 return true ;
467473}
468474
469- function requestPaint ( ) { }
475+ function requestPaint ( ) {
476+ needsPaint = true ;
477+ }
470478
471479function forceFrameRate ( fps : number ) {
472480 if ( fps < 0 || fps > 125 ) {
@@ -486,6 +494,7 @@ function forceFrameRate(fps: number) {
486494}
487495
488496const performWorkUntilDeadline = ( ) = > {
497+ needsPaint = false ;
489498 if ( isMessageLoopRunning ) {
490499 const currentTime = getCurrentTime ( ) ;
491500 // Keep track of the start time so we can measure how long the main thread
You can’t perform that action at this time.
0 commit comments