@@ -22,6 +22,7 @@ export class Scheduler {
2222 delayedRenders : Fiber [ ] = [ ] ;
2323 cancelledNodes : Set < ComponentNode > = new Set ( ) ;
2424 processing = false ;
25+ tasksProcessPromise : Promise < void > = Promise . resolve ( ) ;
2526
2627 constructor ( ) {
2728 this . requestAnimationFrame = Scheduler . requestAnimationFrame ;
@@ -65,43 +66,46 @@ export class Scheduler {
6566 }
6667 this . processing = true ;
6768 this . frame = 0 ;
68- for ( let node of this . cancelledNodes ) {
69- node . _destroy ( ) ;
70- }
71- this . cancelledNodes . clear ( ) ;
72- for ( let fiber of this . tasks ) {
73- if ( fiber . root !== fiber ) {
74- this . tasks . delete ( fiber ) ;
75- continue ;
76- }
77- const hasError = fibersInError . has ( fiber ) ;
78- if ( hasError && fiber . counter !== 0 ) {
79- this . tasks . delete ( fiber ) ;
80- continue ;
81- }
82- if ( fiber . node . status === STATUS . DESTROYED ) {
83- this . tasks . delete ( fiber ) ;
84- continue ;
69+ this . tasksProcessPromise = new Promise ( ( resolve ) => {
70+ for ( let node of this . cancelledNodes ) {
71+ node . _destroy ( ) ;
8572 }
86- if ( fiber . counter === 0 ) {
87- if ( ! hasError ) {
88- fiber . complete ( ) ;
73+ this . cancelledNodes . clear ( ) ;
74+ for ( let fiber of this . tasks ) {
75+ if ( fiber . root !== fiber ) {
76+ this . tasks . delete ( fiber ) ;
77+ continue ;
78+ }
79+ const hasError = fibersInError . has ( fiber ) ;
80+ if ( hasError && fiber . counter !== 0 ) {
81+ this . tasks . delete ( fiber ) ;
82+ continue ;
8983 }
90- // at this point, the fiber should have been applied to the DOM, so we can
91- // remove it from the task list. If it is not the case, it means that there
92- // was an error and an error handler triggered a new rendering that recycled
93- // the fiber, so in that case, we actually want to keep the fiber around,
94- // otherwise it will just be ignored.
95- if ( fiber . appliedToDom ) {
84+ if ( fiber . node . status === STATUS . DESTROYED ) {
9685 this . tasks . delete ( fiber ) ;
86+ continue ;
87+ }
88+ if ( fiber . counter === 0 ) {
89+ if ( ! hasError ) {
90+ fiber . complete ( ) ;
91+ }
92+ // at this point, the fiber should have been applied to the DOM, so we can
93+ // remove it from the task list. If it is not the case, it means that there
94+ // was an error and an error handler triggered a new rendering that recycled
95+ // the fiber, so in that case, we actually want to keep the fiber around,
96+ // otherwise it will just be ignored.
97+ if ( fiber . appliedToDom ) {
98+ this . tasks . delete ( fiber ) ;
99+ }
97100 }
98101 }
99- }
100- for ( let task of this . tasks ) {
101- if ( task . node . status === STATUS . DESTROYED ) {
102- this . tasks . delete ( task ) ;
102+ for ( let task of this . tasks ) {
103+ if ( task . node . status === STATUS . DESTROYED ) {
104+ this . tasks . delete ( task ) ;
105+ }
103106 }
104- }
105- this . processing = false ;
107+ this . processing = false ;
108+ resolve ( ) ;
109+ } ) ;
106110 }
107111}
0 commit comments