From e0fd9e67fce5748990ff4a4d0802878ded230771 Mon Sep 17 00:00:00 2001 From: Ricky Date: Tue, 19 Jan 2021 17:34:08 -0500 Subject: [PATCH] Use update lane priority in work loop (#20621) --- .../src/ReactFiberWorkLoop.new.js | 35 +++++-------------- .../src/ReactFiberWorkLoop.old.js | 35 +++++-------------- 2 files changed, 18 insertions(+), 52 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js index 4eafe42585043..a04b522e57ba0 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js @@ -448,12 +448,9 @@ export function requestUpdateLane(fiber: Fiber): Lane { // To do that, we're replacing it with an update lane priority. const schedulerPriority = getCurrentPriorityLevel(); - // The old behavior was using the priority level of the Scheduler. - // This couples React to the Scheduler internals, so we're replacing it - // with the currentUpdateLanePriority above. As an example of how this - // could be problematic, if we're not inside `Scheduler.runWithPriority`, - // then we'll get the priority of the current running Scheduler task, - // which is probably not what we want. + // Find the correct lane based on priorities. Ideally, this would just be + // the update lane priority, but for now we're also checking for discrete + // updates and falling back to the scheduler priority. let lane; if ( // TODO: Temporary. We're removing the concept of discrete updates. @@ -461,31 +458,17 @@ export function requestUpdateLane(fiber: Fiber): Lane { schedulerPriority === UserBlockingSchedulerPriority ) { lane = findUpdateLane(InputDiscreteLanePriority, currentEventWipLanes); + } else if ( + decoupleUpdatePriorityFromScheduler && + getCurrentUpdateLanePriority() !== NoLanePriority + ) { + const currentLanePriority = getCurrentUpdateLanePriority(); + lane = findUpdateLane(currentLanePriority, currentEventWipLanes); } else { const schedulerLanePriority = schedulerPriorityToLanePriority( schedulerPriority, ); - if (decoupleUpdatePriorityFromScheduler) { - // In the new strategy, we will track the current update lane priority - // inside React and use that priority to select a lane for this update. - // For now, we're just logging when they're different so we can assess. - const currentUpdateLanePriority = getCurrentUpdateLanePriority(); - - if ( - schedulerLanePriority !== currentUpdateLanePriority && - currentUpdateLanePriority !== NoLanePriority - ) { - if (__DEV__) { - console.error( - 'Expected current scheduler lane priority %s to match current update lane priority %s', - schedulerLanePriority, - currentUpdateLanePriority, - ); - } - } - } - lane = findUpdateLane(schedulerLanePriority, currentEventWipLanes); } diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js index 7ed5b098982af..65c966d53110d 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js @@ -448,12 +448,9 @@ export function requestUpdateLane(fiber: Fiber): Lane { // To do that, we're replacing it with an update lane priority. const schedulerPriority = getCurrentPriorityLevel(); - // The old behavior was using the priority level of the Scheduler. - // This couples React to the Scheduler internals, so we're replacing it - // with the currentUpdateLanePriority above. As an example of how this - // could be problematic, if we're not inside `Scheduler.runWithPriority`, - // then we'll get the priority of the current running Scheduler task, - // which is probably not what we want. + // Find the correct lane based on priorities. Ideally, this would just be + // the update lane priority, but for now we're also checking for discrete + // updates and falling back to the scheduler priority. let lane; if ( // TODO: Temporary. We're removing the concept of discrete updates. @@ -461,31 +458,17 @@ export function requestUpdateLane(fiber: Fiber): Lane { schedulerPriority === UserBlockingSchedulerPriority ) { lane = findUpdateLane(InputDiscreteLanePriority, currentEventWipLanes); + } else if ( + decoupleUpdatePriorityFromScheduler && + getCurrentUpdateLanePriority() !== NoLanePriority + ) { + const currentLanePriority = getCurrentUpdateLanePriority(); + lane = findUpdateLane(currentLanePriority, currentEventWipLanes); } else { const schedulerLanePriority = schedulerPriorityToLanePriority( schedulerPriority, ); - if (decoupleUpdatePriorityFromScheduler) { - // In the new strategy, we will track the current update lane priority - // inside React and use that priority to select a lane for this update. - // For now, we're just logging when they're different so we can assess. - const currentUpdateLanePriority = getCurrentUpdateLanePriority(); - - if ( - schedulerLanePriority !== currentUpdateLanePriority && - currentUpdateLanePriority !== NoLanePriority - ) { - if (__DEV__) { - console.error( - 'Expected current scheduler lane priority %s to match current update lane priority %s', - schedulerLanePriority, - currentUpdateLanePriority, - ); - } - } - } - lane = findUpdateLane(schedulerLanePriority, currentEventWipLanes); }