Skip to content

Commit

Permalink
Minor updates from review
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii committed Jun 12, 2020
1 parent 0993d6d commit 3cace0b
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 154 deletions.
72 changes: 33 additions & 39 deletions packages/react-reconciler/src/ReactFiberHooks.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ import {NoMode, BlockingMode} from './ReactTypeOfMode';
import {
NoLane,
NoLanes,
DefaultLanePriority,
TransitionShortLanePriority,
TransitionLongLanePriority,
InputContinuousLanePriority,
isSubsetOfLanes,
mergeLanes,
removeLanes,
markRootEntangled,
markRootMutableRead,
getCurrentLanePriority,
setCurrentLanePriority,
getCurrentUpdateLanePriority,
setCurrentUpdateLanePriority,
schedulerPriorityToLanePriority,
} from './ReactFiberLane';
import {readContext} from './ReactFiberNewContext.new';
Expand Down Expand Up @@ -1503,43 +1504,36 @@ function rerenderDeferredValue<T>(

function startTransition(setPending, config, callback) {
const priorityLevel = getCurrentPriorityLevel();
const previousLanePriority = getCurrentLanePriority();
try {
setCurrentLanePriority(
priorityLevel < UserBlockingPriority
? InputContinuousLanePriority
: schedulerPriorityToLanePriority(priorityLevel),
);
runWithPriority(
priorityLevel < UserBlockingPriority
? UserBlockingPriority
: priorityLevel,
() => {
setPending(true);
},
);
const previousLanePriority = getCurrentUpdateLanePriority();
setCurrentUpdateLanePriority(InputContinuousLanePriority);
runWithPriority(
priorityLevel < UserBlockingPriority
? UserBlockingPriority
: priorityLevel,
() => {
setPending(true);
},
);

setCurrentLanePriority(
priorityLevel > NormalPriority
? DefaultLanePriority
: schedulerPriorityToLanePriority(priorityLevel),
);
runWithPriority(
priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
() => {
const previousConfig = ReactCurrentBatchConfig.suspense;
ReactCurrentBatchConfig.suspense = config === undefined ? null : config;
try {
setPending(false);
callback();
} finally {
ReactCurrentBatchConfig.suspense = previousConfig;
}
},
);
} finally {
setCurrentLanePriority(previousLanePriority);
}
setCurrentUpdateLanePriority(
config === undefined || config.timeoutMs === undefined || (config.timeoutMs | 0) < 10000
? TransitionShortLanePriority
: TransitionLongLanePriority
);
runWithPriority(
priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
() => {
const previousConfig = ReactCurrentBatchConfig.suspense;
ReactCurrentBatchConfig.suspense = config === undefined ? null : config;
try {
setPending(false);
callback();
} finally {
setCurrentUpdateLanePriority(previousLanePriority);
ReactCurrentBatchConfig.suspense = previousConfig;
}
},
);
}

function mountTransition(
Expand Down
72 changes: 33 additions & 39 deletions packages/react-reconciler/src/ReactFiberHooks.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ import {NoMode, BlockingMode} from './ReactTypeOfMode';
import {
NoLane,
NoLanes,
DefaultLanePriority,
TransitionShortLanePriority,
TransitionLongLanePriority,
InputContinuousLanePriority,
isSubsetOfLanes,
mergeLanes,
removeLanes,
markRootEntangled,
markRootMutableRead,
getCurrentLanePriority,
setCurrentLanePriority,
getCurrentUpdateLanePriority,
setCurrentUpdateLanePriority,
schedulerPriorityToLanePriority,
} from './ReactFiberLane';
import {readContext} from './ReactFiberNewContext.old';
Expand Down Expand Up @@ -1503,43 +1504,36 @@ function rerenderDeferredValue<T>(

function startTransition(setPending, config, callback) {
const priorityLevel = getCurrentPriorityLevel();
const previousLanePriority = getCurrentLanePriority();
try {
setCurrentLanePriority(
priorityLevel < UserBlockingPriority
? InputContinuousLanePriority
: schedulerPriorityToLanePriority(priorityLevel),
);
runWithPriority(
priorityLevel < UserBlockingPriority
? UserBlockingPriority
: priorityLevel,
() => {
setPending(true);
},
);
const previousLanePriority = getCurrentUpdateLanePriority();
setCurrentUpdateLanePriority(InputContinuousLanePriority)
runWithPriority(
priorityLevel < UserBlockingPriority
? UserBlockingPriority
: priorityLevel,
() => {
setPending(true);
},
);

setCurrentLanePriority(
priorityLevel > NormalPriority
? DefaultLanePriority
: schedulerPriorityToLanePriority(priorityLevel),
);
runWithPriority(
priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
() => {
const previousConfig = ReactCurrentBatchConfig.suspense;
ReactCurrentBatchConfig.suspense = config === undefined ? null : config;
try {
setPending(false);
callback();
} finally {
ReactCurrentBatchConfig.suspense = previousConfig;
}
},
);
} finally {
setCurrentLanePriority(previousLanePriority);
}
setCurrentUpdateLanePriority(
config === undefined || config.timeoutMs === undefined || (config.timeoutMs | 0) < 10000
? TransitionShortLanePriority
: TransitionLongLanePriority
);
runWithPriority(
priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
() => {
const previousConfig = ReactCurrentBatchConfig.suspense;
ReactCurrentBatchConfig.suspense = config === undefined ? null : config;
try {
setPending(false);
callback();
} finally {
setCurrentUpdateLanePriority(previousLanePriority);
ReactCurrentBatchConfig.suspense = previousConfig;
}
},
);
}

function mountTransition(
Expand Down
10 changes: 5 additions & 5 deletions packages/react-reconciler/src/ReactFiberLane.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ export const OffscreenLane: Lane = /* */ 0b1000000000000000000

export const NoTimestamp = -1;

let currentLanePriority: LanePriority = NoLanePriority;
let currentUpdateLanePriority: LanePriority = NoLanePriority;

export function getCurrentLanePriority(): LanePriority {
return currentLanePriority;
export function getCurrentUpdateLanePriority(): LanePriority {
return currentUpdateLanePriority;
}

export function setCurrentLanePriority(newLanePriority: LanePriority) {
currentLanePriority = newLanePriority;
export function setCurrentUpdateLanePriority(newLanePriority: LanePriority) {
currentUpdateLanePriority = newLanePriority;
}

// "Registers" used to "return" multiple values
Expand Down
58 changes: 29 additions & 29 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ import {
hasUpdatePriority,
getNextLanes,
returnNextLanesPriority,
setCurrentLanePriority,
getCurrentLanePriority,
setCurrentUpdateLanePriority,
getCurrentUpdateLanePriority,
markStarvedLanesAsExpired,
getLanesToRetrySynchronouslyOnError,
markRootUpdated,
Expand Down Expand Up @@ -423,9 +423,9 @@ export function requestUpdateLane(
);
} else if (
enableCurrentLanePriority &&
getCurrentLanePriority() !== NoLanePriority
getCurrentUpdateLanePriority() !== NoLanePriority
) {
const currentLanePriority = getCurrentLanePriority();
const currentLanePriority = getCurrentUpdateLanePriority();
lane = findUpdateLane(currentLanePriority, currentEventWipLanes);
} else {
// TODO: If we're not inside `runWithPriority`, this returns the priority
Expand Down Expand Up @@ -1078,12 +1078,12 @@ export function flushDiscreteUpdates() {

export function deferredUpdates<A>(fn: () => A): A {
// TODO: Remove in favor of Scheduler.next
const previousLanePriority = getCurrentLanePriority();
const previousLanePriority = getCurrentUpdateLanePriority();
try {
setCurrentLanePriority(DefaultLanePriority);
setCurrentUpdateLanePriority(DefaultLanePriority);
return runWithPriority(NormalSchedulerPriority, fn);
} finally {
setCurrentLanePriority(previousLanePriority);
setCurrentUpdateLanePriority(previousLanePriority);
}
}

Expand Down Expand Up @@ -1139,16 +1139,16 @@ export function discreteUpdates<A, B, C, D, R>(
): R {
const prevExecutionContext = executionContext;
executionContext |= DiscreteEventContext;
const previousLanePriority = getCurrentLanePriority();
const previousLanePriority = getCurrentUpdateLanePriority();
try {
setCurrentLanePriority(InputDiscreteLanePriority);
setCurrentUpdateLanePriority(InputDiscreteLanePriority);
// Should this
return runWithPriority(
UserBlockingSchedulerPriority,
fn.bind(null, a, b, c, d),
);
} finally {
setCurrentLanePriority(previousLanePriority);
setCurrentUpdateLanePriority(previousLanePriority);
executionContext = prevExecutionContext;
if (executionContext === NoContext) {
// Flush the immediate callbacks that were scheduled during this batch
Expand Down Expand Up @@ -1185,16 +1185,16 @@ export function flushSync<A, R>(fn: A => R, a: A): R {
return fn(a);
}
executionContext |= BatchedContext;
const previousLanePriority = getCurrentLanePriority();
const previousLanePriority = getCurrentUpdateLanePriority();
try {
setCurrentLanePriority(SyncLanePriority);
setCurrentUpdateLanePriority(SyncLanePriority);
if (fn) {
return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a));
} else {
return (undefined: $FlowFixMe);
}
} finally {
setCurrentLanePriority(previousLanePriority);
setCurrentUpdateLanePriority(previousLanePriority);
executionContext = prevExecutionContext;
// Flush the immediate callbacks that were scheduled during this batch.
// Note that this will happen even if batchedUpdates is higher up
Expand All @@ -1206,12 +1206,12 @@ export function flushSync<A, R>(fn: A => R, a: A): R {
export function flushControlled(fn: () => mixed): void {
const prevExecutionContext = executionContext;
executionContext |= BatchedContext;
const previousLanePriority = getCurrentLanePriority();
const previousLanePriority = getCurrentUpdateLanePriority();
try {
setCurrentLanePriority(SyncLanePriority);
setCurrentUpdateLanePriority(SyncLanePriority);
runWithPriority(ImmediateSchedulerPriority, fn);
} finally {
setCurrentLanePriority(previousLanePriority);
setCurrentUpdateLanePriority(previousLanePriority);
executionContext = prevExecutionContext;
if (executionContext === NoContext) {
// Flush the immediate callbacks that were scheduled during this batch
Expand Down Expand Up @@ -1802,20 +1802,17 @@ function resetChildLanes(completedWork: Fiber) {

function commitRoot(root) {
const renderPriorityLevel = getCurrentPriorityLevel();
const previousLanePriority = getCurrentLanePriority();
try {
setCurrentLanePriority(SyncLanePriority);
runWithPriority(
ImmediateSchedulerPriority,
commitRootImpl.bind(null, root, renderPriorityLevel),
);
} finally {
setCurrentLanePriority(previousLanePriority);
}
runWithPriority(
ImmediateSchedulerPriority,
commitRootImpl.bind(null, root, renderPriorityLevel),
);
return null;
}

function commitRootImpl(root, renderPriorityLevel) {
const previousLanePriority = getCurrentUpdateLanePriority();
setCurrentUpdateLanePriority(SyncLanePriority);

do {
// `flushPassiveEffects` will call `flushSyncUpdateQueue` at the end, which
// means `flushPassiveEffects` will sometimes result in additional
Expand Down Expand Up @@ -2111,6 +2108,9 @@ function commitRootImpl(root, renderPriorityLevel) {
// additional work on this root is scheduled.
ensureRootIsScheduled(root, now());

// Reset the priority to the previous non-sync value.
setCurrentUpdateLanePriority(previousLanePriority);

if (hasUncaughtError) {
hasUncaughtError = false;
const error = firstUncaughtError;
Expand Down Expand Up @@ -2280,12 +2280,12 @@ export function flushPassiveEffects() {
? NormalSchedulerPriority
: pendingPassiveEffectsRenderPriority;
pendingPassiveEffectsRenderPriority = NoSchedulerPriority;
const previousLanePriority = getCurrentLanePriority();
const previousLanePriority = getCurrentUpdateLanePriority();
try {
setCurrentLanePriority(schedulerPriorityToLanePriority(priorityLevel));
setCurrentUpdateLanePriority(schedulerPriorityToLanePriority(priorityLevel));
return runWithPriority(priorityLevel, flushPassiveEffectsImpl);
} finally {
setCurrentLanePriority(previousLanePriority);
setCurrentUpdateLanePriority(previousLanePriority);
}
}
}
Expand Down
Loading

0 comments on commit 3cace0b

Please sign in to comment.