Skip to content

Commit 32ff428

Browse files
authored
Add feature flag for setting update lane priority (#19401)
* Add feature flag for setting update lane priority * Remove second feature flag * Refactor feature flag locations * Add missing else
1 parent 5bdd4c8 commit 32ff428

7 files changed

+479
-223
lines changed

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

+23-7
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ import {
3838
import getEventTarget from './getEventTarget';
3939
import {getClosestInstanceFromNode} from '../client/ReactDOMComponentTree';
4040

41-
import {enableLegacyFBSupport} from 'shared/ReactFeatureFlags';
41+
import {
42+
enableLegacyFBSupport,
43+
decoupleUpdatePriorityFromScheduler,
44+
} from 'shared/ReactFeatureFlags';
4245
import {
4346
UserBlockingEvent,
4447
ContinuousEvent,
@@ -147,10 +150,25 @@ function dispatchUserBlockingUpdate(
147150
container,
148151
nativeEvent,
149152
) {
150-
// TODO: Double wrapping is necessary while we decouple Scheduler priority.
151-
const previousPriority = getCurrentUpdateLanePriority();
152-
try {
153-
setCurrentUpdateLanePriority(InputContinuousLanePriority);
153+
if (decoupleUpdatePriorityFromScheduler) {
154+
const previousPriority = getCurrentUpdateLanePriority();
155+
try {
156+
// TODO: Double wrapping is necessary while we decouple Scheduler priority.
157+
setCurrentUpdateLanePriority(InputContinuousLanePriority);
158+
runWithPriority(
159+
UserBlockingPriority,
160+
dispatchEvent.bind(
161+
null,
162+
domEventName,
163+
eventSystemFlags,
164+
container,
165+
nativeEvent,
166+
),
167+
);
168+
} finally {
169+
setCurrentUpdateLanePriority(previousPriority);
170+
}
171+
} else {
154172
runWithPriority(
155173
UserBlockingPriority,
156174
dispatchEvent.bind(
@@ -161,8 +179,6 @@ function dispatchUserBlockingUpdate(
161179
nativeEvent,
162180
),
163181
);
164-
} finally {
165-
setCurrentUpdateLanePriority(previousPriority);
166182
}
167183
}
168184

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

+57-26
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
enableDebugTracing,
2727
enableSchedulingProfiler,
2828
enableNewReconciler,
29+
decoupleUpdatePriorityFromScheduler,
2930
} from 'shared/ReactFeatureFlags';
3031

3132
import {NoMode, BlockingMode, DebugTracingMode} from './ReactTypeOfMode';
@@ -1506,34 +1507,64 @@ function rerenderDeferredValue<T>(
15061507

15071508
function startTransition(setPending, config, callback) {
15081509
const priorityLevel = getCurrentPriorityLevel();
1509-
const previousLanePriority = getCurrentUpdateLanePriority();
1510-
setCurrentUpdateLanePriority(
1511-
higherLanePriority(previousLanePriority, InputContinuousLanePriority),
1512-
);
1513-
runWithPriority(
1514-
priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel,
1515-
() => {
1516-
setPending(true);
1517-
},
1518-
);
1510+
if (decoupleUpdatePriorityFromScheduler) {
1511+
const previousLanePriority = getCurrentUpdateLanePriority();
1512+
setCurrentUpdateLanePriority(
1513+
higherLanePriority(previousLanePriority, InputContinuousLanePriority),
1514+
);
15191515

1520-
// If there's no SuspenseConfig set, we'll use the DefaultLanePriority for this transition.
1521-
setCurrentUpdateLanePriority(DefaultLanePriority);
1516+
runWithPriority(
1517+
priorityLevel < UserBlockingPriority
1518+
? UserBlockingPriority
1519+
: priorityLevel,
1520+
() => {
1521+
setPending(true);
1522+
},
1523+
);
15221524

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-
);
1525+
// If there's no SuspenseConfig set, we'll use the DefaultLanePriority for this transition.
1526+
setCurrentUpdateLanePriority(DefaultLanePriority);
1527+
1528+
runWithPriority(
1529+
priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
1530+
() => {
1531+
const previousConfig = ReactCurrentBatchConfig.suspense;
1532+
ReactCurrentBatchConfig.suspense = config === undefined ? null : config;
1533+
try {
1534+
setPending(false);
1535+
callback();
1536+
} finally {
1537+
if (decoupleUpdatePriorityFromScheduler) {
1538+
setCurrentUpdateLanePriority(previousLanePriority);
1539+
}
1540+
ReactCurrentBatchConfig.suspense = previousConfig;
1541+
}
1542+
},
1543+
);
1544+
} else {
1545+
runWithPriority(
1546+
priorityLevel < UserBlockingPriority
1547+
? UserBlockingPriority
1548+
: priorityLevel,
1549+
() => {
1550+
setPending(true);
1551+
},
1552+
);
1553+
1554+
runWithPriority(
1555+
priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
1556+
() => {
1557+
const previousConfig = ReactCurrentBatchConfig.suspense;
1558+
ReactCurrentBatchConfig.suspense = config === undefined ? null : config;
1559+
try {
1560+
setPending(false);
1561+
callback();
1562+
} finally {
1563+
ReactCurrentBatchConfig.suspense = previousConfig;
1564+
}
1565+
},
1566+
);
1567+
}
15371568
}
15381569

15391570
function mountTransition(

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

+57-26
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
enableDebugTracing,
2727
enableSchedulingProfiler,
2828
enableNewReconciler,
29+
decoupleUpdatePriorityFromScheduler,
2930
} from 'shared/ReactFeatureFlags';
3031

3132
import {NoMode, BlockingMode, DebugTracingMode} from './ReactTypeOfMode';
@@ -1505,34 +1506,64 @@ function rerenderDeferredValue<T>(
15051506

15061507
function startTransition(setPending, config, callback) {
15071508
const priorityLevel = getCurrentPriorityLevel();
1508-
const previousLanePriority = getCurrentUpdateLanePriority();
1509-
setCurrentUpdateLanePriority(
1510-
higherLanePriority(previousLanePriority, InputContinuousLanePriority),
1511-
);
1512-
runWithPriority(
1513-
priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel,
1514-
() => {
1515-
setPending(true);
1516-
},
1517-
);
1509+
if (decoupleUpdatePriorityFromScheduler) {
1510+
const previousLanePriority = getCurrentUpdateLanePriority();
1511+
setCurrentUpdateLanePriority(
1512+
higherLanePriority(previousLanePriority, InputContinuousLanePriority),
1513+
);
15181514

1519-
// If there's no SuspenseConfig set, we'll use the DefaultLanePriority for this transition.
1520-
setCurrentUpdateLanePriority(DefaultLanePriority);
1515+
runWithPriority(
1516+
priorityLevel < UserBlockingPriority
1517+
? UserBlockingPriority
1518+
: priorityLevel,
1519+
() => {
1520+
setPending(true);
1521+
},
1522+
);
15211523

1522-
runWithPriority(
1523-
priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
1524-
() => {
1525-
const previousConfig = ReactCurrentBatchConfig.suspense;
1526-
ReactCurrentBatchConfig.suspense = config === undefined ? null : config;
1527-
try {
1528-
setPending(false);
1529-
callback();
1530-
} finally {
1531-
setCurrentUpdateLanePriority(previousLanePriority);
1532-
ReactCurrentBatchConfig.suspense = previousConfig;
1533-
}
1534-
},
1535-
);
1524+
// If there's no SuspenseConfig set, we'll use the DefaultLanePriority for this transition.
1525+
setCurrentUpdateLanePriority(DefaultLanePriority);
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+
if (decoupleUpdatePriorityFromScheduler) {
1537+
setCurrentUpdateLanePriority(previousLanePriority);
1538+
}
1539+
ReactCurrentBatchConfig.suspense = previousConfig;
1540+
}
1541+
},
1542+
);
1543+
} else {
1544+
runWithPriority(
1545+
priorityLevel < UserBlockingPriority
1546+
? UserBlockingPriority
1547+
: priorityLevel,
1548+
() => {
1549+
setPending(true);
1550+
},
1551+
);
1552+
1553+
runWithPriority(
1554+
priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
1555+
() => {
1556+
const previousConfig = ReactCurrentBatchConfig.suspense;
1557+
ReactCurrentBatchConfig.suspense = config === undefined ? null : config;
1558+
try {
1559+
setPending(false);
1560+
callback();
1561+
} finally {
1562+
ReactCurrentBatchConfig.suspense = previousConfig;
1563+
}
1564+
},
1565+
);
1566+
}
15361567
}
15371568

15381569
function mountTransition(

0 commit comments

Comments
 (0)