Use update lane priority in work loop (#20621)
Ricky committed
Jan 19, 2021 at 17:34 UTC
e0fd9e67fce5748990ff4a4d0802878ded230771
2 files changed
+18
-52
packages/react-reconciler/src/ReactFiberWorkLoop.new.js
+9
-26
@@ -448,12 +448,9 @@ export function requestUpdateLane(fiber: Fiber): Lane {
448
// To do that, we're replacing it with an update lane priority.
449
const schedulerPriority = getCurrentPriorityLevel();
450
451
- // The old behavior was using the priority level of the Scheduler.
452
- // This couples React to the Scheduler internals, so we're replacing it
453
- // with the currentUpdateLanePriority above. As an example of how this
454
- // could be problematic, if we're not inside `Scheduler.runWithPriority`,
455
- // then we'll get the priority of the current running Scheduler task,
456
- // which is probably not what we want.
451
+ // Find the correct lane based on priorities. Ideally, this would just be
452
+ // the update lane priority, but for now we're also checking for discrete
453
+ // updates and falling back to the scheduler priority.
454
let lane;
455
if (
456
// TODO: Temporary. We're removing the concept of discrete updates.
@@ -461,31 +458,17 @@ export function requestUpdateLane(fiber: Fiber): Lane {
458
schedulerPriority === UserBlockingSchedulerPriority
459
) {
460
lane = findUpdateLane(InputDiscreteLanePriority, currentEventWipLanes);
461
+ } else if (
462
+ decoupleUpdatePriorityFromScheduler &&
463
+ getCurrentUpdateLanePriority() !== NoLanePriority
464
+ ) {
465
+ const currentLanePriority = getCurrentUpdateLanePriority();
466
+ lane = findUpdateLane(currentLanePriority, currentEventWipLanes);
467
} else {
468
const schedulerLanePriority = schedulerPriorityToLanePriority(
469
schedulerPriority,
470
);
471
469
- if (decoupleUpdatePriorityFromScheduler) {
470
- // In the new strategy, we will track the current update lane priority
471
- // inside React and use that priority to select a lane for this update.
472
- // For now, we're just logging when they're different so we can assess.
473
- const currentUpdateLanePriority = getCurrentUpdateLanePriority();
474
-
475
- if (
476
- schedulerLanePriority !== currentUpdateLanePriority &&
477
- currentUpdateLanePriority !== NoLanePriority
478
- ) {
479
- if (__DEV__) {
480
- console.error(
481
- 'Expected current scheduler lane priority %s to match current update lane priority %s',
482
- schedulerLanePriority,
483
- currentUpdateLanePriority,
484
- );
485
- }
486
- }
487
- }
488
-
472
lane = findUpdateLane(schedulerLanePriority, currentEventWipLanes);
473
}
474
packages/react-reconciler/src/ReactFiberWorkLoop.old.js
+9
-26
@@ -448,12 +448,9 @@ export function requestUpdateLane(fiber: Fiber): Lane {
448
// To do that, we're replacing it with an update lane priority.
449
const schedulerPriority = getCurrentPriorityLevel();
450
451
- // The old behavior was using the priority level of the Scheduler.
452
- // This couples React to the Scheduler internals, so we're replacing it
453
- // with the currentUpdateLanePriority above. As an example of how this
454
- // could be problematic, if we're not inside `Scheduler.runWithPriority`,
455
- // then we'll get the priority of the current running Scheduler task,
456
- // which is probably not what we want.
451
+ // Find the correct lane based on priorities. Ideally, this would just be
452
+ // the update lane priority, but for now we're also checking for discrete
453
+ // updates and falling back to the scheduler priority.
454
let lane;
455
if (
456
// TODO: Temporary. We're removing the concept of discrete updates.
@@ -461,31 +458,17 @@ export function requestUpdateLane(fiber: Fiber): Lane {
458
schedulerPriority === UserBlockingSchedulerPriority
459
) {
460
lane = findUpdateLane(InputDiscreteLanePriority, currentEventWipLanes);
461
+ } else if (
462
+ decoupleUpdatePriorityFromScheduler &&
463
+ getCurrentUpdateLanePriority() !== NoLanePriority
464
+ ) {
465
+ const currentLanePriority = getCurrentUpdateLanePriority();
466
+ lane = findUpdateLane(currentLanePriority, currentEventWipLanes);
467
} else {
468
const schedulerLanePriority = schedulerPriorityToLanePriority(
469
schedulerPriority,
470
);
471
469
- if (decoupleUpdatePriorityFromScheduler) {
470
- // In the new strategy, we will track the current update lane priority
471
- // inside React and use that priority to select a lane for this update.
472
- // For now, we're just logging when they're different so we can assess.
473
- const currentUpdateLanePriority = getCurrentUpdateLanePriority();
474
-
475
- if (
476
- schedulerLanePriority !== currentUpdateLanePriority &&
477
- currentUpdateLanePriority !== NoLanePriority
478
- ) {
479
- if (__DEV__) {
480
- console.error(
481
- 'Expected current scheduler lane priority %s to match current update lane priority %s',
482
- schedulerLanePriority,
483
- currentUpdateLanePriority,
484
- );
485
- }
486
- }
487
- }
488
-
472
lane = findUpdateLane(schedulerLanePriority, currentEventWipLanes);
473
}
474