Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0036347

Browse files
committedJun 12, 2020
Minor updates from review
1 parent 0993d6d commit 0036347

9 files changed

+147
-154
lines changed
 

‎packages/react-reconciler/src/ReactFiberHooks.new.js

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ import {NoMode, BlockingMode} from './ReactTypeOfMode';
3030
import {
3131
NoLane,
3232
NoLanes,
33-
DefaultLanePriority,
33+
TransitionShortLanePriority,
34+
TransitionLongLanePriority,
3435
InputContinuousLanePriority,
3536
isSubsetOfLanes,
3637
mergeLanes,
3738
removeLanes,
3839
markRootEntangled,
3940
markRootMutableRead,
40-
getCurrentLanePriority,
41-
setCurrentLanePriority,
41+
getCurrentUpdateLanePriority,
42+
setCurrentUpdateLanePriority,
4243
schedulerPriorityToLanePriority,
4344
} from './ReactFiberLane';
4445
import {readContext} from './ReactFiberNewContext.new';
@@ -1503,43 +1504,36 @@ function rerenderDeferredValue<T>(
15031504

15041505
function startTransition(setPending, config, callback) {
15051506
const priorityLevel = getCurrentPriorityLevel();
1506-
const previousLanePriority = getCurrentLanePriority();
1507-
try {
1508-
setCurrentLanePriority(
1509-
priorityLevel < UserBlockingPriority
1510-
? InputContinuousLanePriority
1511-
: schedulerPriorityToLanePriority(priorityLevel),
1512-
);
1513-
runWithPriority(
1514-
priorityLevel < UserBlockingPriority
1515-
? UserBlockingPriority
1516-
: priorityLevel,
1517-
() => {
1518-
setPending(true);
1519-
},
1520-
);
1507+
const previousLanePriority = getCurrentUpdateLanePriority();
1508+
setCurrentUpdateLanePriority(InputContinuousLanePriority);
1509+
runWithPriority(
1510+
priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel,
1511+
() => {
1512+
setPending(true);
1513+
},
1514+
);
15211515

1522-
setCurrentLanePriority(
1523-
priorityLevel > NormalPriority
1524-
? DefaultLanePriority
1525-
: schedulerPriorityToLanePriority(priorityLevel),
1526-
);
1527-
runWithPriority(
1528-
priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
1529-
() => {
1530-
const previousConfig = ReactCurrentBatchConfig.suspense;
1531-
ReactCurrentBatchConfig.suspense = config === undefined ? null : config;
1532-
try {
1533-
setPending(false);
1534-
callback();
1535-
} finally {
1536-
ReactCurrentBatchConfig.suspense = previousConfig;
1537-
}
1538-
},
1539-
);
1540-
} finally {
1541-
setCurrentLanePriority(previousLanePriority);
1542-
}
1516+
setCurrentUpdateLanePriority(
1517+
config === undefined ||
1518+
config.timeoutMs === undefined ||
1519+
(config.timeoutMs | 0) < 10000
1520+
? TransitionShortLanePriority
1521+
: TransitionLongLanePriority,
1522+
);
1523+
runWithPriority(
1524+
priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
1525+
() => {
1526+
const previousConfig = ReactCurrentBatchConfig.suspense;
1527+
ReactCurrentBatchConfig.suspense = config === undefined ? null : config;
1528+
try {
1529+
setPending(false);
1530+
callback();
1531+
} finally {
1532+
setCurrentUpdateLanePriority(previousLanePriority);
1533+
ReactCurrentBatchConfig.suspense = previousConfig;
1534+
}
1535+
},
1536+
);
15431537
}
15441538

15451539
function mountTransition(

‎packages/react-reconciler/src/ReactFiberHooks.old.js

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ import {NoMode, BlockingMode} from './ReactTypeOfMode';
3030
import {
3131
NoLane,
3232
NoLanes,
33-
DefaultLanePriority,
33+
TransitionShortLanePriority,
34+
TransitionLongLanePriority,
3435
InputContinuousLanePriority,
3536
isSubsetOfLanes,
3637
mergeLanes,
3738
removeLanes,
3839
markRootEntangled,
3940
markRootMutableRead,
40-
getCurrentLanePriority,
41-
setCurrentLanePriority,
41+
getCurrentUpdateLanePriority,
42+
setCurrentUpdateLanePriority,
4243
schedulerPriorityToLanePriority,
4344
} from './ReactFiberLane';
4445
import {readContext} from './ReactFiberNewContext.old';
@@ -1503,43 +1504,36 @@ function rerenderDeferredValue<T>(
15031504

15041505
function startTransition(setPending, config, callback) {
15051506
const priorityLevel = getCurrentPriorityLevel();
1506-
const previousLanePriority = getCurrentLanePriority();
1507-
try {
1508-
setCurrentLanePriority(
1509-
priorityLevel < UserBlockingPriority
1510-
? InputContinuousLanePriority
1511-
: schedulerPriorityToLanePriority(priorityLevel),
1512-
);
1513-
runWithPriority(
1514-
priorityLevel < UserBlockingPriority
1515-
? UserBlockingPriority
1516-
: priorityLevel,
1517-
() => {
1518-
setPending(true);
1519-
},
1520-
);
1507+
const previousLanePriority = getCurrentUpdateLanePriority();
1508+
setCurrentUpdateLanePriority(InputContinuousLanePriority);
1509+
runWithPriority(
1510+
priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel,
1511+
() => {
1512+
setPending(true);
1513+
},
1514+
);
15211515

1522-
setCurrentLanePriority(
1523-
priorityLevel > NormalPriority
1524-
? DefaultLanePriority
1525-
: schedulerPriorityToLanePriority(priorityLevel),
1526-
);
1527-
runWithPriority(
1528-
priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
1529-
() => {
1530-
const previousConfig = ReactCurrentBatchConfig.suspense;
1531-
ReactCurrentBatchConfig.suspense = config === undefined ? null : config;
1532-
try {
1533-
setPending(false);
1534-
callback();
1535-
} finally {
1536-
ReactCurrentBatchConfig.suspense = previousConfig;
1537-
}
1538-
},
1539-
);
1540-
} finally {
1541-
setCurrentLanePriority(previousLanePriority);
1542-
}
1516+
setCurrentUpdateLanePriority(
1517+
config === undefined ||
1518+
config.timeoutMs === undefined ||
1519+
(config.timeoutMs | 0) < 10000
1520+
? TransitionShortLanePriority
1521+
: TransitionLongLanePriority,
1522+
);
1523+
runWithPriority(
1524+
priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
1525+
() => {
1526+
const previousConfig = ReactCurrentBatchConfig.suspense;
1527+
ReactCurrentBatchConfig.suspense = config === undefined ? null : config;
1528+
try {
1529+
setPending(false);
1530+
callback();
1531+
} finally {
1532+
setCurrentUpdateLanePriority(previousLanePriority);
1533+
ReactCurrentBatchConfig.suspense = previousConfig;
1534+
}
1535+
},
1536+
);
15431537
}
15441538

15451539
function mountTransition(

‎packages/react-reconciler/src/ReactFiberLane.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ export const OffscreenLane: Lane = /* */ 0b1000000000000000000
120120

121121
export const NoTimestamp = -1;
122122

123-
let currentLanePriority: LanePriority = NoLanePriority;
123+
let currentUpdateLanePriority: LanePriority = NoLanePriority;
124124

125-
export function getCurrentLanePriority(): LanePriority {
126-
return currentLanePriority;
125+
export function getCurrentUpdateLanePriority(): LanePriority {
126+
return currentUpdateLanePriority;
127127
}
128128

129-
export function setCurrentLanePriority(newLanePriority: LanePriority) {
130-
currentLanePriority = newLanePriority;
129+
export function setCurrentUpdateLanePriority(newLanePriority: LanePriority) {
130+
currentUpdateLanePriority = newLanePriority;
131131
}
132132

133133
// "Registers" used to "return" multiple values

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

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ import {
132132
hasUpdatePriority,
133133
getNextLanes,
134134
returnNextLanesPriority,
135-
setCurrentLanePriority,
136-
getCurrentLanePriority,
135+
setCurrentUpdateLanePriority,
136+
getCurrentUpdateLanePriority,
137137
markStarvedLanesAsExpired,
138138
getLanesToRetrySynchronouslyOnError,
139139
markRootUpdated,
@@ -423,9 +423,9 @@ export function requestUpdateLane(
423423
);
424424
} else if (
425425
enableCurrentLanePriority &&
426-
getCurrentLanePriority() !== NoLanePriority
426+
getCurrentUpdateLanePriority() !== NoLanePriority
427427
) {
428-
const currentLanePriority = getCurrentLanePriority();
428+
const currentLanePriority = getCurrentUpdateLanePriority();
429429
lane = findUpdateLane(currentLanePriority, currentEventWipLanes);
430430
} else {
431431
// TODO: If we're not inside `runWithPriority`, this returns the priority
@@ -1078,12 +1078,12 @@ export function flushDiscreteUpdates() {
10781078

10791079
export function deferredUpdates<A>(fn: () => A): A {
10801080
// TODO: Remove in favor of Scheduler.next
1081-
const previousLanePriority = getCurrentLanePriority();
1081+
const previousLanePriority = getCurrentUpdateLanePriority();
10821082
try {
1083-
setCurrentLanePriority(DefaultLanePriority);
1083+
setCurrentUpdateLanePriority(DefaultLanePriority);
10841084
return runWithPriority(NormalSchedulerPriority, fn);
10851085
} finally {
1086-
setCurrentLanePriority(previousLanePriority);
1086+
setCurrentUpdateLanePriority(previousLanePriority);
10871087
}
10881088
}
10891089

@@ -1139,16 +1139,16 @@ export function discreteUpdates<A, B, C, D, R>(
11391139
): R {
11401140
const prevExecutionContext = executionContext;
11411141
executionContext |= DiscreteEventContext;
1142-
const previousLanePriority = getCurrentLanePriority();
1142+
const previousLanePriority = getCurrentUpdateLanePriority();
11431143
try {
1144-
setCurrentLanePriority(InputDiscreteLanePriority);
1144+
setCurrentUpdateLanePriority(InputDiscreteLanePriority);
11451145
// Should this
11461146
return runWithPriority(
11471147
UserBlockingSchedulerPriority,
11481148
fn.bind(null, a, b, c, d),
11491149
);
11501150
} finally {
1151-
setCurrentLanePriority(previousLanePriority);
1151+
setCurrentUpdateLanePriority(previousLanePriority);
11521152
executionContext = prevExecutionContext;
11531153
if (executionContext === NoContext) {
11541154
// Flush the immediate callbacks that were scheduled during this batch
@@ -1185,16 +1185,16 @@ export function flushSync<A, R>(fn: A => R, a: A): R {
11851185
return fn(a);
11861186
}
11871187
executionContext |= BatchedContext;
1188-
const previousLanePriority = getCurrentLanePriority();
1188+
const previousLanePriority = getCurrentUpdateLanePriority();
11891189
try {
1190-
setCurrentLanePriority(SyncLanePriority);
1190+
setCurrentUpdateLanePriority(SyncLanePriority);
11911191
if (fn) {
11921192
return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a));
11931193
} else {
11941194
return (undefined: $FlowFixMe);
11951195
}
11961196
} finally {
1197-
setCurrentLanePriority(previousLanePriority);
1197+
setCurrentUpdateLanePriority(previousLanePriority);
11981198
executionContext = prevExecutionContext;
11991199
// Flush the immediate callbacks that were scheduled during this batch.
12001200
// Note that this will happen even if batchedUpdates is higher up
@@ -1206,12 +1206,12 @@ export function flushSync<A, R>(fn: A => R, a: A): R {
12061206
export function flushControlled(fn: () => mixed): void {
12071207
const prevExecutionContext = executionContext;
12081208
executionContext |= BatchedContext;
1209-
const previousLanePriority = getCurrentLanePriority();
1209+
const previousLanePriority = getCurrentUpdateLanePriority();
12101210
try {
1211-
setCurrentLanePriority(SyncLanePriority);
1211+
setCurrentUpdateLanePriority(SyncLanePriority);
12121212
runWithPriority(ImmediateSchedulerPriority, fn);
12131213
} finally {
1214-
setCurrentLanePriority(previousLanePriority);
1214+
setCurrentUpdateLanePriority(previousLanePriority);
12151215
executionContext = prevExecutionContext;
12161216
if (executionContext === NoContext) {
12171217
// Flush the immediate callbacks that were scheduled during this batch
@@ -1802,20 +1802,17 @@ function resetChildLanes(completedWork: Fiber) {
18021802

18031803
function commitRoot(root) {
18041804
const renderPriorityLevel = getCurrentPriorityLevel();
1805-
const previousLanePriority = getCurrentLanePriority();
1806-
try {
1807-
setCurrentLanePriority(SyncLanePriority);
1808-
runWithPriority(
1809-
ImmediateSchedulerPriority,
1810-
commitRootImpl.bind(null, root, renderPriorityLevel),
1811-
);
1812-
} finally {
1813-
setCurrentLanePriority(previousLanePriority);
1814-
}
1805+
runWithPriority(
1806+
ImmediateSchedulerPriority,
1807+
commitRootImpl.bind(null, root, renderPriorityLevel),
1808+
);
18151809
return null;
18161810
}
18171811

18181812
function commitRootImpl(root, renderPriorityLevel) {
1813+
const previousLanePriority = getCurrentUpdateLanePriority();
1814+
setCurrentUpdateLanePriority(SyncLanePriority);
1815+
18191816
do {
18201817
// `flushPassiveEffects` will call `flushSyncUpdateQueue` at the end, which
18211818
// means `flushPassiveEffects` will sometimes result in additional
@@ -2111,6 +2108,9 @@ function commitRootImpl(root, renderPriorityLevel) {
21112108
// additional work on this root is scheduled.
21122109
ensureRootIsScheduled(root, now());
21132110

2111+
// Reset the priority to the previous non-sync value.
2112+
setCurrentUpdateLanePriority(previousLanePriority);
2113+
21142114
if (hasUncaughtError) {
21152115
hasUncaughtError = false;
21162116
const error = firstUncaughtError;
@@ -2280,12 +2280,14 @@ export function flushPassiveEffects() {
22802280
? NormalSchedulerPriority
22812281
: pendingPassiveEffectsRenderPriority;
22822282
pendingPassiveEffectsRenderPriority = NoSchedulerPriority;
2283-
const previousLanePriority = getCurrentLanePriority();
2283+
const previousLanePriority = getCurrentUpdateLanePriority();
22842284
try {
2285-
setCurrentLanePriority(schedulerPriorityToLanePriority(priorityLevel));
2285+
setCurrentUpdateLanePriority(
2286+
schedulerPriorityToLanePriority(priorityLevel),
2287+
);
22862288
return runWithPriority(priorityLevel, flushPassiveEffectsImpl);
22872289
} finally {
2288-
setCurrentLanePriority(previousLanePriority);
2290+
setCurrentUpdateLanePriority(previousLanePriority);
22892291
}
22902292
}
22912293
}

0 commit comments

Comments
 (0)
Please sign in to comment.