Skip to content

Commit e0fd9e6

Browse files
authored
Use update lane priority in work loop (#20621)
1 parent 58e8304 commit e0fd9e6

File tree

2 files changed

+18
-52
lines changed

2 files changed

+18
-52
lines changed

packages/react-reconciler/src/ReactFiberWorkLoop.new.js

+9-26
Original file line numberDiff line numberDiff line change
@@ -448,44 +448,27 @@ export function requestUpdateLane(fiber: Fiber): Lane {
448448
// To do that, we're replacing it with an update lane priority.
449449
const schedulerPriority = getCurrentPriorityLevel();
450450

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.
457454
let lane;
458455
if (
459456
// TODO: Temporary. We're removing the concept of discrete updates.
460457
(executionContext & DiscreteEventContext) !== NoContext &&
461458
schedulerPriority === UserBlockingSchedulerPriority
462459
) {
463460
lane = findUpdateLane(InputDiscreteLanePriority, currentEventWipLanes);
461+
} else if (
462+
decoupleUpdatePriorityFromScheduler &&
463+
getCurrentUpdateLanePriority() !== NoLanePriority
464+
) {
465+
const currentLanePriority = getCurrentUpdateLanePriority();
466+
lane = findUpdateLane(currentLanePriority, currentEventWipLanes);
464467
} else {
465468
const schedulerLanePriority = schedulerPriorityToLanePriority(
466469
schedulerPriority,
467470
);
468471

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-
489472
lane = findUpdateLane(schedulerLanePriority, currentEventWipLanes);
490473
}
491474

packages/react-reconciler/src/ReactFiberWorkLoop.old.js

+9-26
Original file line numberDiff line numberDiff line change
@@ -448,44 +448,27 @@ export function requestUpdateLane(fiber: Fiber): Lane {
448448
// To do that, we're replacing it with an update lane priority.
449449
const schedulerPriority = getCurrentPriorityLevel();
450450

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.
457454
let lane;
458455
if (
459456
// TODO: Temporary. We're removing the concept of discrete updates.
460457
(executionContext & DiscreteEventContext) !== NoContext &&
461458
schedulerPriority === UserBlockingSchedulerPriority
462459
) {
463460
lane = findUpdateLane(InputDiscreteLanePriority, currentEventWipLanes);
461+
} else if (
462+
decoupleUpdatePriorityFromScheduler &&
463+
getCurrentUpdateLanePriority() !== NoLanePriority
464+
) {
465+
const currentLanePriority = getCurrentUpdateLanePriority();
466+
lane = findUpdateLane(currentLanePriority, currentEventWipLanes);
464467
} else {
465468
const schedulerLanePriority = schedulerPriorityToLanePriority(
466469
schedulerPriority,
467470
);
468471

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-
489472
lane = findUpdateLane(schedulerLanePriority, currentEventWipLanes);
490473
}
491474

0 commit comments

Comments
 (0)