Move priority context change to findNextUnitOfWork
...rather than changing it on every unit of work.
Andrew Clark committed
Dec 13, 2016 at 19:07 UTC
e1b733fa8382f74dd790964993856ce5a85bf363
1 file changed
+8
-7
src/renderers/shared/fiber/ReactFiberScheduler.js
+8
-7
@@ -159,6 +159,9 @@ module.exports = function<T, P, I, TI, C, CX>(config : HostConfig<T, P, I, TI, C
159
}
160
}
161
162
+ // findNextUnitOfWork mutates the current priority context. It is reset after
163
+ // after the workLoop exits, so never call findNextUnitOfWork from outside
164
+ // the work loop.
165
function findNextUnitOfWork() {
166
// Clear out roots with no more work on them, or if they have uncaught errors
167
while (nextScheduledRoot && nextScheduledRoot.current.pendingWorkPriority === NoWork) {
@@ -195,6 +198,7 @@ module.exports = function<T, P, I, TI, C, CX>(config : HostConfig<T, P, I, TI, C
198
}
199
if (highestPriorityRoot) {
200
nextPriorityLevel = highestPriorityLevel;
201
+ priorityContext = nextPriorityLevel;
202
return cloneFiber(
203
highestPriorityRoot.current,
204
highestPriorityLevel
@@ -497,11 +501,7 @@ module.exports = function<T, P, I, TI, C, CX>(config : HostConfig<T, P, I, TI, C
501
ReactFiberInstrumentation.debugTool.onWillBeginWork(workInProgress);
502
}
503
// See if beginning this work spawns more work.
500
-
501
- priorityContextBeforeReconciliation = priorityContext;
502
- priorityContext = nextPriorityLevel;
504
let next = beginWork(current, workInProgress, nextPriorityLevel);
504
- priorityContext = priorityContextBeforeReconciliation;
505
506
if (__DEV__ && ReactFiberInstrumentation.debugTool) {
507
ReactFiberInstrumentation.debugTool.onDidBeginWork(workInProgress);
@@ -540,10 +540,7 @@ module.exports = function<T, P, I, TI, C, CX>(config : HostConfig<T, P, I, TI, C
540
ReactFiberInstrumentation.debugTool.onWillBeginWork(workInProgress);
541
}
542
// See if beginning this work spawns more work.
543
- priorityContextBeforeReconciliation = priorityContext;
544
- priorityContext = nextPriorityLevel;
543
let next = beginFailedWork(current, workInProgress, nextPriorityLevel);
546
- priorityContext = priorityContextBeforeReconciliation;
544
545
if (__DEV__ && ReactFiberInstrumentation.debugTool) {
546
ReactFiberInstrumentation.debugTool.onDidBeginWork(workInProgress);
@@ -689,6 +686,8 @@ module.exports = function<T, P, I, TI, C, CX>(config : HostConfig<T, P, I, TI, C
686
// operations must happen within workLoop, which is extracted to a
687
// separate function so that it can be optimized by the JS engine.
688
try {
689
+ priorityContextBeforeReconciliation = priorityContext;
690
+ priorityContext = nextPriorityLevel;
691
deadlineHasExpired = workLoop(priorityLevel, deadline, deadlineHasExpired);
692
} catch (error) {
693
// We caught an error during either the begin or complete phases.
@@ -724,6 +723,8 @@ module.exports = function<T, P, I, TI, C, CX>(config : HostConfig<T, P, I, TI, C
723
}
724
// Continue performing work
725
continue;
726
+ } finally {
727
+ priorityContext = priorityContextBeforeReconciliation;
728
}
729
730
// Stop performing work