Skip to content

Commit da6cce6

Browse files
committed
Add feature flag for setting update lane priority
1 parent b23ea02 commit da6cce6

17 files changed

+206
-80
lines changed

packages/react-dom/src/events/DeprecatedDOMEventResponderSystem.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ import {
3333
executeUserEventHandler,
3434
} from './ReactDOMUpdateBatching';
3535
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
36-
import {enableDeprecatedFlareAPI} from 'shared/ReactFeatureFlags';
36+
import {
37+
enableDeprecatedFlareAPI,
38+
enableSetUpdateLanePriority,
39+
} from 'shared/ReactFeatureFlags';
3740
import invariant from 'shared/invariant';
3841

3942
import {getClosestInstanceFromNode} from '../client/ReactDOMComponentTree';
@@ -108,14 +111,21 @@ const eventResponderContext: ReactDOMResponderContext = {
108111
break;
109112
}
110113
case UserBlockingEvent: {
111-
const previousPriority = getCurrentUpdateLanePriority();
112-
try {
113-
setCurrentUpdateLanePriority(InputContinuousLanePriority);
114+
if (enableSetUpdateLanePriority) {
115+
// TODO: Double wrapping is necessary while we decouple Scheduler priority.
116+
const previousPriority = getCurrentUpdateLanePriority();
117+
try {
118+
setCurrentUpdateLanePriority(InputContinuousLanePriority);
119+
runWithPriority(UserBlockingPriority, () =>
120+
executeUserEventHandler(eventListener, eventValue),
121+
);
122+
} finally {
123+
setCurrentUpdateLanePriority(previousPriority);
124+
}
125+
} else {
114126
runWithPriority(UserBlockingPriority, () =>
115127
executeUserEventHandler(eventListener, eventValue),
116128
);
117-
} finally {
118-
setCurrentUpdateLanePriority(previousPriority);
119129
}
120130
break;
121131
}

packages/react-dom/src/events/ReactDOMEventListener.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import {getClosestInstanceFromNode} from '../client/ReactDOMComponentTree';
4444
import {
4545
enableDeprecatedFlareAPI,
4646
enableLegacyFBSupport,
47+
enableSetUpdateLanePriority,
4748
} from 'shared/ReactFeatureFlags';
4849
import {
4950
UserBlockingEvent,
@@ -153,10 +154,25 @@ function dispatchUserBlockingUpdate(
153154
container,
154155
nativeEvent,
155156
) {
156-
// TODO: Double wrapping is necessary while we decouple Scheduler priority.
157-
const previousPriority = getCurrentUpdateLanePriority();
158-
try {
159-
setCurrentUpdateLanePriority(InputContinuousLanePriority);
157+
if (enableSetUpdateLanePriority) {
158+
const previousPriority = getCurrentUpdateLanePriority();
159+
try {
160+
// TODO: Double wrapping is necessary while we decouple Scheduler priority.
161+
setCurrentUpdateLanePriority(InputContinuousLanePriority);
162+
runWithPriority(
163+
UserBlockingPriority,
164+
dispatchEvent.bind(
165+
null,
166+
topLevelType,
167+
eventSystemFlags,
168+
container,
169+
nativeEvent,
170+
),
171+
);
172+
} finally {
173+
setCurrentUpdateLanePriority(previousPriority);
174+
}
175+
} else {
160176
runWithPriority(
161177
UserBlockingPriority,
162178
dispatchEvent.bind(
@@ -167,8 +183,6 @@ function dispatchUserBlockingUpdate(
167183
nativeEvent,
168184
),
169185
);
170-
} finally {
171-
setCurrentUpdateLanePriority(previousPriority);
172186
}
173187
}
174188

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
enableDebugTracing,
2929
enableSchedulingProfiler,
3030
enableNewReconciler,
31+
enableSetUpdateLanePriority,
3132
} from 'shared/ReactFeatureFlags';
3233

3334
import {NoMode, BlockingMode, DebugTracingMode} from './ReactTypeOfMode';
@@ -1509,19 +1510,24 @@ function rerenderDeferredValue<T>(
15091510

15101511
function startTransition(setPending, config, callback) {
15111512
const priorityLevel = getCurrentPriorityLevel();
1512-
const previousLanePriority = getCurrentUpdateLanePriority();
1513-
setCurrentUpdateLanePriority(
1514-
higherLanePriority(previousLanePriority, InputContinuousLanePriority),
1515-
);
1513+
let previousLanePriority;
1514+
if (enableSetUpdateLanePriority) {
1515+
previousLanePriority = getCurrentUpdateLanePriority();
1516+
setCurrentUpdateLanePriority(
1517+
higherLanePriority(previousLanePriority, InputContinuousLanePriority),
1518+
);
1519+
}
15161520
runWithPriority(
15171521
priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel,
15181522
() => {
15191523
setPending(true);
15201524
},
15211525
);
15221526

1523-
// If there's no SuspenseConfig set, we'll use the DefaultLanePriority for this transition.
1524-
setCurrentUpdateLanePriority(DefaultLanePriority);
1527+
if (enableSetUpdateLanePriority) {
1528+
// If there's no SuspenseConfig set, we'll use the DefaultLanePriority for this transition.
1529+
setCurrentUpdateLanePriority(DefaultLanePriority);
1530+
}
15251531

15261532
runWithPriority(
15271533
priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
@@ -1532,7 +1538,9 @@ function startTransition(setPending, config, callback) {
15321538
setPending(false);
15331539
callback();
15341540
} finally {
1535-
setCurrentUpdateLanePriority(previousLanePriority);
1541+
if (enableSetUpdateLanePriority && previousLanePriority != null) {
1542+
setCurrentUpdateLanePriority(previousLanePriority);
1543+
}
15361544
ReactCurrentBatchConfig.suspense = previousConfig;
15371545
}
15381546
},

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
enableDebugTracing,
2929
enableSchedulingProfiler,
3030
enableNewReconciler,
31+
enableSetUpdateLanePriority,
3132
} from 'shared/ReactFeatureFlags';
3233

3334
import {NoMode, BlockingMode, DebugTracingMode} from './ReactTypeOfMode';
@@ -1509,19 +1510,24 @@ function rerenderDeferredValue<T>(
15091510

15101511
function startTransition(setPending, config, callback) {
15111512
const priorityLevel = getCurrentPriorityLevel();
1512-
const previousLanePriority = getCurrentUpdateLanePriority();
1513-
setCurrentUpdateLanePriority(
1514-
higherLanePriority(previousLanePriority, InputContinuousLanePriority),
1515-
);
1513+
let previousLanePriority;
1514+
if (enableSetUpdateLanePriority) {
1515+
previousLanePriority = getCurrentUpdateLanePriority();
1516+
setCurrentUpdateLanePriority(
1517+
higherLanePriority(previousLanePriority, InputContinuousLanePriority),
1518+
);
1519+
}
15161520
runWithPriority(
15171521
priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel,
15181522
() => {
15191523
setPending(true);
15201524
},
15211525
);
15221526

1523-
// If there's no SuspenseConfig set, we'll use the DefaultLanePriority for this transition.
1524-
setCurrentUpdateLanePriority(DefaultLanePriority);
1527+
if (enableSetUpdateLanePriority) {
1528+
// If there's no SuspenseConfig set, we'll use the DefaultLanePriority for this transition.
1529+
setCurrentUpdateLanePriority(DefaultLanePriority);
1530+
}
15251531

15261532
runWithPriority(
15271533
priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
@@ -1532,7 +1538,9 @@ function startTransition(setPending, config, callback) {
15321538
setPending(false);
15331539
callback();
15341540
} finally {
1535-
setCurrentUpdateLanePriority(previousLanePriority);
1541+
if (enableSetUpdateLanePriority && previousLanePriority != null) {
1542+
setCurrentUpdateLanePriority(previousLanePriority);
1543+
}
15361544
ReactCurrentBatchConfig.suspense = previousConfig;
15371545
}
15381546
},

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

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
enableDebugTracing,
3131
enableSchedulingProfiler,
3232
enableScopeAPI,
33+
enableSetUpdateLanePriority,
3334
} from 'shared/ReactFeatureFlags';
3435
import ReactSharedInternals from 'shared/ReactSharedInternals';
3536
import invariant from 'shared/invariant';
@@ -477,7 +478,7 @@ export function requestUpdateLane(
477478
schedulerPriority,
478479
);
479480

480-
if (decoupleUpdatePriorityFromScheduler) {
481+
if (enableSetUpdateLanePriority && decoupleUpdatePriorityFromScheduler) {
481482
// In the new strategy, we will track the current update lane priority
482483
// inside React and use that priority to select a lane for this update.
483484
// For now, we're just logging when they're different so we can assess.
@@ -1142,13 +1143,17 @@ export function flushDiscreteUpdates() {
11421143
}
11431144

11441145
export function deferredUpdates<A>(fn: () => A): A {
1145-
// TODO: Remove in favor of Scheduler.next
1146-
const previousLanePriority = getCurrentUpdateLanePriority();
1146+
let previousLanePriority;
11471147
try {
1148-
setCurrentUpdateLanePriority(DefaultLanePriority);
1148+
if (enableSetUpdateLanePriority) {
1149+
previousLanePriority = getCurrentUpdateLanePriority();
1150+
setCurrentUpdateLanePriority(DefaultLanePriority);
1151+
}
11491152
return runWithPriority(NormalSchedulerPriority, fn);
11501153
} finally {
1151-
setCurrentUpdateLanePriority(previousLanePriority);
1154+
if (enableSetUpdateLanePriority && previousLanePriority != null) {
1155+
setCurrentUpdateLanePriority(previousLanePriority);
1156+
}
11521157
}
11531158
}
11541159

@@ -1204,16 +1209,21 @@ export function discreteUpdates<A, B, C, D, R>(
12041209
): R {
12051210
const prevExecutionContext = executionContext;
12061211
executionContext |= DiscreteEventContext;
1207-
const previousLanePriority = getCurrentUpdateLanePriority();
1212+
let previousLanePriority;
12081213
try {
1209-
setCurrentUpdateLanePriority(InputDiscreteLanePriority);
1214+
if (enableSetUpdateLanePriority) {
1215+
previousLanePriority = getCurrentUpdateLanePriority();
1216+
setCurrentUpdateLanePriority(InputDiscreteLanePriority);
1217+
}
12101218
// Should this
12111219
return runWithPriority(
12121220
UserBlockingSchedulerPriority,
12131221
fn.bind(null, a, b, c, d),
12141222
);
12151223
} finally {
1216-
setCurrentUpdateLanePriority(previousLanePriority);
1224+
if (enableSetUpdateLanePriority && previousLanePriority != null) {
1225+
setCurrentUpdateLanePriority(previousLanePriority);
1226+
}
12171227
executionContext = prevExecutionContext;
12181228
if (executionContext === NoContext) {
12191229
// Flush the immediate callbacks that were scheduled during this batch
@@ -1250,16 +1260,21 @@ export function flushSync<A, R>(fn: A => R, a: A): R {
12501260
return fn(a);
12511261
}
12521262
executionContext |= BatchedContext;
1253-
const previousLanePriority = getCurrentUpdateLanePriority();
1263+
let previousLanePriority;
12541264
try {
1255-
setCurrentUpdateLanePriority(SyncLanePriority);
1265+
if (enableSetUpdateLanePriority) {
1266+
previousLanePriority = getCurrentUpdateLanePriority();
1267+
setCurrentUpdateLanePriority(SyncLanePriority);
1268+
}
12561269
if (fn) {
12571270
return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a));
12581271
} else {
12591272
return (undefined: $FlowFixMe);
12601273
}
12611274
} finally {
1262-
setCurrentUpdateLanePriority(previousLanePriority);
1275+
if (enableSetUpdateLanePriority && previousLanePriority != null) {
1276+
setCurrentUpdateLanePriority(previousLanePriority);
1277+
}
12631278
executionContext = prevExecutionContext;
12641279
// Flush the immediate callbacks that were scheduled during this batch.
12651280
// Note that this will happen even if batchedUpdates is higher up
@@ -1271,12 +1286,17 @@ export function flushSync<A, R>(fn: A => R, a: A): R {
12711286
export function flushControlled(fn: () => mixed): void {
12721287
const prevExecutionContext = executionContext;
12731288
executionContext |= BatchedContext;
1274-
const previousLanePriority = getCurrentUpdateLanePriority();
1289+
let previousLanePriority;
12751290
try {
1276-
setCurrentUpdateLanePriority(SyncLanePriority);
1291+
if (enableSetUpdateLanePriority) {
1292+
previousLanePriority = getCurrentUpdateLanePriority();
1293+
setCurrentUpdateLanePriority(SyncLanePriority);
1294+
}
12771295
runWithPriority(ImmediateSchedulerPriority, fn);
12781296
} finally {
1279-
setCurrentUpdateLanePriority(previousLanePriority);
1297+
if (enableSetUpdateLanePriority && previousLanePriority != null) {
1298+
setCurrentUpdateLanePriority(previousLanePriority);
1299+
}
12801300
executionContext = prevExecutionContext;
12811301
if (executionContext === NoContext) {
12821302
// Flush the immediate callbacks that were scheduled during this batch
@@ -2090,8 +2110,11 @@ function commitRootImpl(root, renderPriorityLevel) {
20902110
}
20912111

20922112
if (firstEffect !== null) {
2093-
const previousLanePriority = getCurrentUpdateLanePriority();
2094-
setCurrentUpdateLanePriority(SyncLanePriority);
2113+
let previousLanePriority;
2114+
if (enableSetUpdateLanePriority) {
2115+
previousLanePriority = getCurrentUpdateLanePriority();
2116+
setCurrentUpdateLanePriority(SyncLanePriority);
2117+
}
20952118

20962119
const prevExecutionContext = executionContext;
20972120
executionContext |= CommitContext;
@@ -2168,8 +2191,10 @@ function commitRootImpl(root, renderPriorityLevel) {
21682191
}
21692192
executionContext = prevExecutionContext;
21702193

2171-
// Reset the priority to the previous non-sync value.
2172-
setCurrentUpdateLanePriority(previousLanePriority);
2194+
if (enableSetUpdateLanePriority && previousLanePriority != null) {
2195+
// Reset the priority to the previous non-sync value.
2196+
setCurrentUpdateLanePriority(previousLanePriority);
2197+
}
21732198
} else {
21742199
// No effects.
21752200
root.current = finishedWork;
@@ -2607,14 +2632,19 @@ export function flushPassiveEffects() {
26072632
? NormalSchedulerPriority
26082633
: pendingPassiveEffectsRenderPriority;
26092634
pendingPassiveEffectsRenderPriority = NoSchedulerPriority;
2610-
const previousLanePriority = getCurrentUpdateLanePriority();
2635+
let previousLanePriority;
26112636
try {
2612-
setCurrentUpdateLanePriority(
2613-
schedulerPriorityToLanePriority(priorityLevel),
2614-
);
2637+
if (enableSetUpdateLanePriority) {
2638+
previousLanePriority = getCurrentUpdateLanePriority();
2639+
setCurrentUpdateLanePriority(
2640+
schedulerPriorityToLanePriority(priorityLevel),
2641+
);
2642+
}
26152643
return runWithPriority(priorityLevel, flushPassiveEffectsImpl);
26162644
} finally {
2617-
setCurrentUpdateLanePriority(previousLanePriority);
2645+
if (enableSetUpdateLanePriority && previousLanePriority != null) {
2646+
setCurrentUpdateLanePriority(previousLanePriority);
2647+
}
26182648
}
26192649
}
26202650
}

0 commit comments

Comments
 (0)