@@ -30,6 +30,7 @@ import {
3030 enableDebugTracing ,
3131 enableSchedulingProfiler ,
3232 enableScopeAPI ,
33+ enableSetUpdateLanePriority ,
3334} from 'shared/ReactFeatureFlags' ;
3435import ReactSharedInternals from 'shared/ReactSharedInternals' ;
3536import 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
11441145export 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 {
12711286export 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