Skip to content

Commit

Permalink
Change warning implementation and startTransition update lane priority
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii committed Jul 6, 2020
1 parent 0d9812c commit 383eb73
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 85 deletions.
13 changes: 4 additions & 9 deletions packages/react-reconciler/src/ReactFiberHooks.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import {NoMode, BlockingMode} from './ReactTypeOfMode';
import {
NoLane,
NoLanes,
TransitionShortLanePriority,
TransitionLongLanePriority,
InputContinuousLanePriority,
isSubsetOfLanes,
mergeLanes,
Expand All @@ -41,6 +39,7 @@ import {
getCurrentUpdateLanePriority,
setCurrentUpdateLanePriority,
higherLanePriority,
DefaultLanePriority,
} from './ReactFiberLane';
import {readContext} from './ReactFiberNewContext.new';
import {createDeprecatedResponderListener} from './ReactFiberDeprecatedEvents.new';
Expand Down Expand Up @@ -1515,13 +1514,9 @@ function startTransition(setPending, config, callback) {
},
);

setCurrentUpdateLanePriority(
config == null ||
config.timeoutMs === undefined ||
(config.timeoutMs | 0) < 10000
? TransitionShortLanePriority
: TransitionLongLanePriority,
);
// If there's no SuspenseConfig set, we'll use the DefaultLanePriority for this transition.
setCurrentUpdateLanePriority(DefaultLanePriority);

runWithPriority(
priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
() => {
Expand Down
13 changes: 4 additions & 9 deletions packages/react-reconciler/src/ReactFiberHooks.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ import {NoMode, BlockingMode, DebugTracingMode} from './ReactTypeOfMode';
import {
NoLane,
NoLanes,
TransitionShortLanePriority,
TransitionLongLanePriority,
InputContinuousLanePriority,
isSubsetOfLanes,
mergeLanes,
Expand All @@ -44,6 +42,7 @@ import {
getCurrentUpdateLanePriority,
setCurrentUpdateLanePriority,
higherLanePriority,
DefaultLanePriority,
} from './ReactFiberLane';
import {readContext} from './ReactFiberNewContext.old';
import {createDeprecatedResponderListener} from './ReactFiberDeprecatedEvents.old';
Expand Down Expand Up @@ -1519,13 +1518,9 @@ function startTransition(setPending, config, callback) {
},
);

setCurrentUpdateLanePriority(
config == null ||
config.timeoutMs === undefined ||
(config.timeoutMs | 0) < 10000
? TransitionShortLanePriority
: TransitionLongLanePriority,
);
// If there's no SuspenseConfig set, we'll use the DefaultLanePriority for this transition.
setCurrentUpdateLanePriority(DefaultLanePriority);

runWithPriority(
priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
() => {
Expand Down
49 changes: 25 additions & 24 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,28 +426,6 @@ export function requestUpdateLane(
// To do that, we're replacing it with an update lane priority.
const schedulerPriority = getCurrentPriorityLevel();

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 updateLaneSchedulerPriority = lanePriorityToSchedulerPriority(
getCurrentUpdateLanePriority(),
);

if (
schedulerPriority !== updateLaneSchedulerPriority &&
updateLaneSchedulerPriority !== NoSchedulerPriority
) {
if (__DEV__) {
console.error(
'Expected current update lane priority %s to match current scheduler priority %s',
updateLaneSchedulerPriority,
schedulerPriority,
);
}
}
}

// 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
Expand All @@ -462,8 +440,31 @@ export function requestUpdateLane(
) {
lane = findUpdateLane(InputDiscreteLanePriority, currentEventWipLanes);
} else {
const lanePriority = schedulerPriorityToLanePriority(schedulerPriority);
lane = findUpdateLane(lanePriority, currentEventWipLanes);
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);
}

return lane;
Expand Down
68 changes: 25 additions & 43 deletions packages/react-reconciler/src/ReactFiberWorkLoop.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,47 +437,6 @@ export function requestUpdateLane(
// To do that, we're replacing it with an update lane priority.
const schedulerPriority = getCurrentPriorityLevel();

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.
const currentUpdateLanePriority = getCurrentUpdateLanePriority();

// The update lane priority will conflict with any callsites using
// Scheduler methods like `runWithPriority` or `next`. Until those
// callsites are migrated, we need to check that the priorities match
// before using the new update lane priority.
const laneSchedulerPriority = lanePriorityToSchedulerPriority(
currentUpdateLanePriority,
);
if (schedulerPriority === laneSchedulerPriority) {
let lane;
if (
currentUpdateLanePriority === TransitionShortLanePriority ||
currentUpdateLanePriority === TransitionLongLanePriority
) {
lane = findTransitionLane(
currentUpdateLanePriority,
currentEventWipLanes,
NoLanes,
);
} else {
lane = findUpdateLane(currentUpdateLanePriority, currentEventWipLanes);
}

return lane;
} else if (currentUpdateLanePriority !== NoLanePriority) {
// If the priorities don't match, log it so we can fix it. Once this
// error stops firing, we can use only the currentUpdateLanePriority.
if (__DEV__) {
console.error(
'Expected current update lane priority %s to match current scheduler priority %s',
lanePriorityToSchedulerPriority(currentUpdateLanePriority),
schedulerPriority,
);
}
}
}

// 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
Expand All @@ -492,8 +451,31 @@ export function requestUpdateLane(
) {
lane = findUpdateLane(InputDiscreteLanePriority, currentEventWipLanes);
} else {
const lanePriority = schedulerPriorityToLanePriority(schedulerPriority);
lane = findUpdateLane(lanePriority, currentEventWipLanes);
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);
}

return lane;
Expand Down

0 comments on commit 383eb73

Please sign in to comment.