From da6cce60e54a2aa299f6df5aaf62ef4576031666 Mon Sep 17 00:00:00 2001 From: Rick Hanlon Date: Wed, 15 Jul 2020 23:31:54 -0400 Subject: [PATCH 1/4] Add feature flag for setting update lane priority --- .../DeprecatedDOMEventResponderSystem.js | 22 ++++-- .../src/events/ReactDOMEventListener.js | 26 +++++-- .../src/ReactFiberHooks.new.js | 22 ++++-- .../src/ReactFiberHooks.old.js | 22 ++++-- .../src/ReactFiberWorkLoop.new.js | 76 +++++++++++++------ .../src/ReactFiberWorkLoop.old.js | 76 +++++++++++++------ .../src/SchedulerWithReactIntegration.new.js | 16 +++- .../src/SchedulerWithReactIntegration.old.js | 16 +++- packages/shared/ReactFeatureFlags.js | 1 + .../forks/ReactFeatureFlags.native-fb.js | 1 + .../forks/ReactFeatureFlags.native-oss.js | 1 + .../forks/ReactFeatureFlags.test-renderer.js | 1 + .../ReactFeatureFlags.test-renderer.www.js | 1 + .../shared/forks/ReactFeatureFlags.testing.js | 1 + .../forks/ReactFeatureFlags.testing.www.js | 1 + .../forks/ReactFeatureFlags.www-dynamic.js | 1 + .../shared/forks/ReactFeatureFlags.www.js | 2 + 17 files changed, 206 insertions(+), 80 deletions(-) diff --git a/packages/react-dom/src/events/DeprecatedDOMEventResponderSystem.js b/packages/react-dom/src/events/DeprecatedDOMEventResponderSystem.js index c1312dccb1792..29ee23a21e73f 100644 --- a/packages/react-dom/src/events/DeprecatedDOMEventResponderSystem.js +++ b/packages/react-dom/src/events/DeprecatedDOMEventResponderSystem.js @@ -33,7 +33,10 @@ import { executeUserEventHandler, } from './ReactDOMUpdateBatching'; import type {Fiber} from 'react-reconciler/src/ReactInternalTypes'; -import {enableDeprecatedFlareAPI} from 'shared/ReactFeatureFlags'; +import { + enableDeprecatedFlareAPI, + enableSetUpdateLanePriority, +} from 'shared/ReactFeatureFlags'; import invariant from 'shared/invariant'; import {getClosestInstanceFromNode} from '../client/ReactDOMComponentTree'; @@ -108,14 +111,21 @@ const eventResponderContext: ReactDOMResponderContext = { break; } case UserBlockingEvent: { - const previousPriority = getCurrentUpdateLanePriority(); - try { - setCurrentUpdateLanePriority(InputContinuousLanePriority); + if (enableSetUpdateLanePriority) { + // TODO: Double wrapping is necessary while we decouple Scheduler priority. + const previousPriority = getCurrentUpdateLanePriority(); + try { + setCurrentUpdateLanePriority(InputContinuousLanePriority); + runWithPriority(UserBlockingPriority, () => + executeUserEventHandler(eventListener, eventValue), + ); + } finally { + setCurrentUpdateLanePriority(previousPriority); + } + } else { runWithPriority(UserBlockingPriority, () => executeUserEventHandler(eventListener, eventValue), ); - } finally { - setCurrentUpdateLanePriority(previousPriority); } break; } diff --git a/packages/react-dom/src/events/ReactDOMEventListener.js b/packages/react-dom/src/events/ReactDOMEventListener.js index fad2d1d56c11a..46c053ee3a375 100644 --- a/packages/react-dom/src/events/ReactDOMEventListener.js +++ b/packages/react-dom/src/events/ReactDOMEventListener.js @@ -44,6 +44,7 @@ import {getClosestInstanceFromNode} from '../client/ReactDOMComponentTree'; import { enableDeprecatedFlareAPI, enableLegacyFBSupport, + enableSetUpdateLanePriority, } from 'shared/ReactFeatureFlags'; import { UserBlockingEvent, @@ -153,10 +154,25 @@ function dispatchUserBlockingUpdate( container, nativeEvent, ) { - // TODO: Double wrapping is necessary while we decouple Scheduler priority. - const previousPriority = getCurrentUpdateLanePriority(); - try { - setCurrentUpdateLanePriority(InputContinuousLanePriority); + if (enableSetUpdateLanePriority) { + const previousPriority = getCurrentUpdateLanePriority(); + try { + // TODO: Double wrapping is necessary while we decouple Scheduler priority. + setCurrentUpdateLanePriority(InputContinuousLanePriority); + runWithPriority( + UserBlockingPriority, + dispatchEvent.bind( + null, + topLevelType, + eventSystemFlags, + container, + nativeEvent, + ), + ); + } finally { + setCurrentUpdateLanePriority(previousPriority); + } + } else { runWithPriority( UserBlockingPriority, dispatchEvent.bind( @@ -167,8 +183,6 @@ function dispatchUserBlockingUpdate( nativeEvent, ), ); - } finally { - setCurrentUpdateLanePriority(previousPriority); } } diff --git a/packages/react-reconciler/src/ReactFiberHooks.new.js b/packages/react-reconciler/src/ReactFiberHooks.new.js index c5f766759e0dc..6cbe2440d329d 100644 --- a/packages/react-reconciler/src/ReactFiberHooks.new.js +++ b/packages/react-reconciler/src/ReactFiberHooks.new.js @@ -28,6 +28,7 @@ import { enableDebugTracing, enableSchedulingProfiler, enableNewReconciler, + enableSetUpdateLanePriority, } from 'shared/ReactFeatureFlags'; import {NoMode, BlockingMode, DebugTracingMode} from './ReactTypeOfMode'; @@ -1509,10 +1510,13 @@ function rerenderDeferredValue( function startTransition(setPending, config, callback) { const priorityLevel = getCurrentPriorityLevel(); - const previousLanePriority = getCurrentUpdateLanePriority(); - setCurrentUpdateLanePriority( - higherLanePriority(previousLanePriority, InputContinuousLanePriority), - ); + let previousLanePriority; + if (enableSetUpdateLanePriority) { + previousLanePriority = getCurrentUpdateLanePriority(); + setCurrentUpdateLanePriority( + higherLanePriority(previousLanePriority, InputContinuousLanePriority), + ); + } runWithPriority( priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel, () => { @@ -1520,8 +1524,10 @@ function startTransition(setPending, config, callback) { }, ); - // If there's no SuspenseConfig set, we'll use the DefaultLanePriority for this transition. - setCurrentUpdateLanePriority(DefaultLanePriority); + if (enableSetUpdateLanePriority) { + // If there's no SuspenseConfig set, we'll use the DefaultLanePriority for this transition. + setCurrentUpdateLanePriority(DefaultLanePriority); + } runWithPriority( priorityLevel > NormalPriority ? NormalPriority : priorityLevel, @@ -1532,7 +1538,9 @@ function startTransition(setPending, config, callback) { setPending(false); callback(); } finally { - setCurrentUpdateLanePriority(previousLanePriority); + if (enableSetUpdateLanePriority && previousLanePriority != null) { + setCurrentUpdateLanePriority(previousLanePriority); + } ReactCurrentBatchConfig.suspense = previousConfig; } }, diff --git a/packages/react-reconciler/src/ReactFiberHooks.old.js b/packages/react-reconciler/src/ReactFiberHooks.old.js index c5d5ba25ac946..3f73ab1cf9c43 100644 --- a/packages/react-reconciler/src/ReactFiberHooks.old.js +++ b/packages/react-reconciler/src/ReactFiberHooks.old.js @@ -28,6 +28,7 @@ import { enableDebugTracing, enableSchedulingProfiler, enableNewReconciler, + enableSetUpdateLanePriority, } from 'shared/ReactFeatureFlags'; import {NoMode, BlockingMode, DebugTracingMode} from './ReactTypeOfMode'; @@ -1509,10 +1510,13 @@ function rerenderDeferredValue( function startTransition(setPending, config, callback) { const priorityLevel = getCurrentPriorityLevel(); - const previousLanePriority = getCurrentUpdateLanePriority(); - setCurrentUpdateLanePriority( - higherLanePriority(previousLanePriority, InputContinuousLanePriority), - ); + let previousLanePriority; + if (enableSetUpdateLanePriority) { + previousLanePriority = getCurrentUpdateLanePriority(); + setCurrentUpdateLanePriority( + higherLanePriority(previousLanePriority, InputContinuousLanePriority), + ); + } runWithPriority( priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel, () => { @@ -1520,8 +1524,10 @@ function startTransition(setPending, config, callback) { }, ); - // If there's no SuspenseConfig set, we'll use the DefaultLanePriority for this transition. - setCurrentUpdateLanePriority(DefaultLanePriority); + if (enableSetUpdateLanePriority) { + // If there's no SuspenseConfig set, we'll use the DefaultLanePriority for this transition. + setCurrentUpdateLanePriority(DefaultLanePriority); + } runWithPriority( priorityLevel > NormalPriority ? NormalPriority : priorityLevel, @@ -1532,7 +1538,9 @@ function startTransition(setPending, config, callback) { setPending(false); callback(); } finally { - setCurrentUpdateLanePriority(previousLanePriority); + if (enableSetUpdateLanePriority && previousLanePriority != null) { + setCurrentUpdateLanePriority(previousLanePriority); + } ReactCurrentBatchConfig.suspense = previousConfig; } }, diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js index bf6e813b2d2fe..81b11272b67d1 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js @@ -30,6 +30,7 @@ import { enableDebugTracing, enableSchedulingProfiler, enableScopeAPI, + enableSetUpdateLanePriority, } from 'shared/ReactFeatureFlags'; import ReactSharedInternals from 'shared/ReactSharedInternals'; import invariant from 'shared/invariant'; @@ -477,7 +478,7 @@ export function requestUpdateLane( schedulerPriority, ); - if (decoupleUpdatePriorityFromScheduler) { + if (enableSetUpdateLanePriority && decoupleUpdatePriorityFromScheduler) { // In the new strategy, we will track the current update lane priority // inside React and use that priority to select a lane for this update. // For now, we're just logging when they're different so we can assess. @@ -1142,13 +1143,17 @@ export function flushDiscreteUpdates() { } export function deferredUpdates(fn: () => A): A { - // TODO: Remove in favor of Scheduler.next - const previousLanePriority = getCurrentUpdateLanePriority(); + let previousLanePriority; try { - setCurrentUpdateLanePriority(DefaultLanePriority); + if (enableSetUpdateLanePriority) { + previousLanePriority = getCurrentUpdateLanePriority(); + setCurrentUpdateLanePriority(DefaultLanePriority); + } return runWithPriority(NormalSchedulerPriority, fn); } finally { - setCurrentUpdateLanePriority(previousLanePriority); + if (enableSetUpdateLanePriority && previousLanePriority != null) { + setCurrentUpdateLanePriority(previousLanePriority); + } } } @@ -1204,16 +1209,21 @@ export function discreteUpdates( ): R { const prevExecutionContext = executionContext; executionContext |= DiscreteEventContext; - const previousLanePriority = getCurrentUpdateLanePriority(); + let previousLanePriority; try { - setCurrentUpdateLanePriority(InputDiscreteLanePriority); + if (enableSetUpdateLanePriority) { + previousLanePriority = getCurrentUpdateLanePriority(); + setCurrentUpdateLanePriority(InputDiscreteLanePriority); + } // Should this return runWithPriority( UserBlockingSchedulerPriority, fn.bind(null, a, b, c, d), ); } finally { - setCurrentUpdateLanePriority(previousLanePriority); + if (enableSetUpdateLanePriority && previousLanePriority != null) { + setCurrentUpdateLanePriority(previousLanePriority); + } executionContext = prevExecutionContext; if (executionContext === NoContext) { // Flush the immediate callbacks that were scheduled during this batch @@ -1250,16 +1260,21 @@ export function flushSync(fn: A => R, a: A): R { return fn(a); } executionContext |= BatchedContext; - const previousLanePriority = getCurrentUpdateLanePriority(); + let previousLanePriority; try { - setCurrentUpdateLanePriority(SyncLanePriority); + if (enableSetUpdateLanePriority) { + previousLanePriority = getCurrentUpdateLanePriority(); + setCurrentUpdateLanePriority(SyncLanePriority); + } if (fn) { return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a)); } else { return (undefined: $FlowFixMe); } } finally { - setCurrentUpdateLanePriority(previousLanePriority); + if (enableSetUpdateLanePriority && previousLanePriority != null) { + 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 @@ -1271,12 +1286,17 @@ export function flushSync(fn: A => R, a: A): R { export function flushControlled(fn: () => mixed): void { const prevExecutionContext = executionContext; executionContext |= BatchedContext; - const previousLanePriority = getCurrentUpdateLanePriority(); + let previousLanePriority; try { - setCurrentUpdateLanePriority(SyncLanePriority); + if (enableSetUpdateLanePriority) { + previousLanePriority = getCurrentUpdateLanePriority(); + setCurrentUpdateLanePriority(SyncLanePriority); + } runWithPriority(ImmediateSchedulerPriority, fn); } finally { - setCurrentUpdateLanePriority(previousLanePriority); + if (enableSetUpdateLanePriority && previousLanePriority != null) { + setCurrentUpdateLanePriority(previousLanePriority); + } executionContext = prevExecutionContext; if (executionContext === NoContext) { // Flush the immediate callbacks that were scheduled during this batch @@ -2090,8 +2110,11 @@ function commitRootImpl(root, renderPriorityLevel) { } if (firstEffect !== null) { - const previousLanePriority = getCurrentUpdateLanePriority(); - setCurrentUpdateLanePriority(SyncLanePriority); + let previousLanePriority; + if (enableSetUpdateLanePriority) { + previousLanePriority = getCurrentUpdateLanePriority(); + setCurrentUpdateLanePriority(SyncLanePriority); + } const prevExecutionContext = executionContext; executionContext |= CommitContext; @@ -2168,8 +2191,10 @@ function commitRootImpl(root, renderPriorityLevel) { } executionContext = prevExecutionContext; - // Reset the priority to the previous non-sync value. - setCurrentUpdateLanePriority(previousLanePriority); + if (enableSetUpdateLanePriority && previousLanePriority != null) { + // Reset the priority to the previous non-sync value. + setCurrentUpdateLanePriority(previousLanePriority); + } } else { // No effects. root.current = finishedWork; @@ -2607,14 +2632,19 @@ export function flushPassiveEffects() { ? NormalSchedulerPriority : pendingPassiveEffectsRenderPriority; pendingPassiveEffectsRenderPriority = NoSchedulerPriority; - const previousLanePriority = getCurrentUpdateLanePriority(); + let previousLanePriority; try { - setCurrentUpdateLanePriority( - schedulerPriorityToLanePriority(priorityLevel), - ); + if (enableSetUpdateLanePriority) { + previousLanePriority = getCurrentUpdateLanePriority(); + setCurrentUpdateLanePriority( + schedulerPriorityToLanePriority(priorityLevel), + ); + } return runWithPriority(priorityLevel, flushPassiveEffectsImpl); } finally { - setCurrentUpdateLanePriority(previousLanePriority); + if (enableSetUpdateLanePriority && previousLanePriority != null) { + setCurrentUpdateLanePriority(previousLanePriority); + } } } } diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js index ea8c7b1a37bda..1f8f1647c92a0 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js @@ -30,6 +30,7 @@ import { enableDebugTracing, enableSchedulingProfiler, enableScopeAPI, + enableSetUpdateLanePriority, } from 'shared/ReactFeatureFlags'; import ReactSharedInternals from 'shared/ReactSharedInternals'; import invariant from 'shared/invariant'; @@ -470,7 +471,7 @@ export function requestUpdateLane( schedulerPriority, ); - if (decoupleUpdatePriorityFromScheduler) { + if (enableSetUpdateLanePriority && decoupleUpdatePriorityFromScheduler) { // In the new strategy, we will track the current update lane priority // inside React and use that priority to select a lane for this update. // For now, we're just logging when they're different so we can assess. @@ -1135,13 +1136,17 @@ export function flushDiscreteUpdates() { } export function deferredUpdates(fn: () => A): A { - // TODO: Remove in favor of Scheduler.next - const previousLanePriority = getCurrentUpdateLanePriority(); + let previousLanePriority; try { - setCurrentUpdateLanePriority(DefaultLanePriority); + if (enableSetUpdateLanePriority) { + previousLanePriority = getCurrentUpdateLanePriority(); + setCurrentUpdateLanePriority(DefaultLanePriority); + } return runWithPriority(NormalSchedulerPriority, fn); } finally { - setCurrentUpdateLanePriority(previousLanePriority); + if (enableSetUpdateLanePriority && previousLanePriority != null) { + setCurrentUpdateLanePriority(previousLanePriority); + } } } @@ -1197,16 +1202,21 @@ export function discreteUpdates( ): R { const prevExecutionContext = executionContext; executionContext |= DiscreteEventContext; - const previousLanePriority = getCurrentUpdateLanePriority(); + let previousLanePriority; try { - setCurrentUpdateLanePriority(InputDiscreteLanePriority); + if (enableSetUpdateLanePriority) { + previousLanePriority = getCurrentUpdateLanePriority(); + setCurrentUpdateLanePriority(InputDiscreteLanePriority); + } // Should this return runWithPriority( UserBlockingSchedulerPriority, fn.bind(null, a, b, c, d), ); } finally { - setCurrentUpdateLanePriority(previousLanePriority); + if (enableSetUpdateLanePriority && previousLanePriority != null) { + setCurrentUpdateLanePriority(previousLanePriority); + } executionContext = prevExecutionContext; if (executionContext === NoContext) { // Flush the immediate callbacks that were scheduled during this batch @@ -1243,16 +1253,21 @@ export function flushSync(fn: A => R, a: A): R { return fn(a); } executionContext |= BatchedContext; - const previousLanePriority = getCurrentUpdateLanePriority(); + let previousLanePriority; try { - setCurrentUpdateLanePriority(SyncLanePriority); + if (enableSetUpdateLanePriority) { + previousLanePriority = getCurrentUpdateLanePriority(); + setCurrentUpdateLanePriority(SyncLanePriority); + } if (fn) { return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a)); } else { return (undefined: $FlowFixMe); } } finally { - setCurrentUpdateLanePriority(previousLanePriority); + if (enableSetUpdateLanePriority && previousLanePriority != null) { + 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 @@ -1264,12 +1279,17 @@ export function flushSync(fn: A => R, a: A): R { export function flushControlled(fn: () => mixed): void { const prevExecutionContext = executionContext; executionContext |= BatchedContext; - const previousLanePriority = getCurrentUpdateLanePriority(); + let previousLanePriority; try { - setCurrentUpdateLanePriority(SyncLanePriority); + if (enableSetUpdateLanePriority) { + previousLanePriority = getCurrentUpdateLanePriority(); + setCurrentUpdateLanePriority(SyncLanePriority); + } runWithPriority(ImmediateSchedulerPriority, fn); } finally { - setCurrentUpdateLanePriority(previousLanePriority); + if (enableSetUpdateLanePriority && previousLanePriority != null) { + setCurrentUpdateLanePriority(previousLanePriority); + } executionContext = prevExecutionContext; if (executionContext === NoContext) { // Flush the immediate callbacks that were scheduled during this batch @@ -2008,8 +2028,11 @@ function commitRootImpl(root, renderPriorityLevel) { } if (firstEffect !== null) { - const previousLanePriority = getCurrentUpdateLanePriority(); - setCurrentUpdateLanePriority(SyncLanePriority); + let previousLanePriority; + if (enableSetUpdateLanePriority) { + previousLanePriority = getCurrentUpdateLanePriority(); + setCurrentUpdateLanePriority(SyncLanePriority); + } const prevExecutionContext = executionContext; executionContext |= CommitContext; @@ -2132,8 +2155,10 @@ function commitRootImpl(root, renderPriorityLevel) { } executionContext = prevExecutionContext; - // Reset the priority to the previous non-sync value. - setCurrentUpdateLanePriority(previousLanePriority); + if (enableSetUpdateLanePriority && previousLanePriority != null) { + // Reset the priority to the previous non-sync value. + setCurrentUpdateLanePriority(previousLanePriority); + } } else { // No effects. root.current = finishedWork; @@ -2451,14 +2476,19 @@ export function flushPassiveEffects() { ? NormalSchedulerPriority : pendingPassiveEffectsRenderPriority; pendingPassiveEffectsRenderPriority = NoSchedulerPriority; - const previousLanePriority = getCurrentUpdateLanePriority(); + let previousLanePriority; try { - setCurrentUpdateLanePriority( - schedulerPriorityToLanePriority(priorityLevel), - ); + if (enableSetUpdateLanePriority) { + previousLanePriority = getCurrentUpdateLanePriority(); + setCurrentUpdateLanePriority( + schedulerPriorityToLanePriority(priorityLevel), + ); + } return runWithPriority(priorityLevel, flushPassiveEffectsImpl); } finally { - setCurrentUpdateLanePriority(previousLanePriority); + if (enableSetUpdateLanePriority && previousLanePriority != null) { + setCurrentUpdateLanePriority(previousLanePriority); + } } } } diff --git a/packages/react-reconciler/src/SchedulerWithReactIntegration.new.js b/packages/react-reconciler/src/SchedulerWithReactIntegration.new.js index 99780f6dbaff3..a865009361866 100644 --- a/packages/react-reconciler/src/SchedulerWithReactIntegration.new.js +++ b/packages/react-reconciler/src/SchedulerWithReactIntegration.new.js @@ -13,7 +13,10 @@ import type {ReactPriorityLevel} from './ReactInternalTypes'; // CommonJS interop named imports. import * as Scheduler from 'scheduler'; import {__interactionsRef} from 'scheduler/tracing'; -import {enableSchedulerTracing} from 'shared/ReactFeatureFlags'; +import { + enableSchedulerTracing, + enableSetUpdateLanePriority, +} from 'shared/ReactFeatureFlags'; import invariant from 'shared/invariant'; import { SyncLanePriority, @@ -176,11 +179,14 @@ function flushSyncCallbackQueueImpl() { // Prevent re-entrancy. isFlushingSyncQueue = true; let i = 0; - const previousLanePriority = getCurrentUpdateLanePriority(); + let previousLanePriority; try { const isSync = true; const queue = syncQueue; - setCurrentUpdateLanePriority(SyncLanePriority); + if (enableSetUpdateLanePriority) { + previousLanePriority = getCurrentUpdateLanePriority(); + setCurrentUpdateLanePriority(SyncLanePriority); + } runWithPriority(ImmediatePriority, () => { for (; i < queue.length; i++) { let callback = queue[i]; @@ -202,7 +208,9 @@ function flushSyncCallbackQueueImpl() { ); throw error; } finally { - setCurrentUpdateLanePriority(previousLanePriority); + if (enableSetUpdateLanePriority && previousLanePriority != null) { + setCurrentUpdateLanePriority(previousLanePriority); + } isFlushingSyncQueue = false; } } diff --git a/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js b/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js index 99780f6dbaff3..a865009361866 100644 --- a/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js +++ b/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js @@ -13,7 +13,10 @@ import type {ReactPriorityLevel} from './ReactInternalTypes'; // CommonJS interop named imports. import * as Scheduler from 'scheduler'; import {__interactionsRef} from 'scheduler/tracing'; -import {enableSchedulerTracing} from 'shared/ReactFeatureFlags'; +import { + enableSchedulerTracing, + enableSetUpdateLanePriority, +} from 'shared/ReactFeatureFlags'; import invariant from 'shared/invariant'; import { SyncLanePriority, @@ -176,11 +179,14 @@ function flushSyncCallbackQueueImpl() { // Prevent re-entrancy. isFlushingSyncQueue = true; let i = 0; - const previousLanePriority = getCurrentUpdateLanePriority(); + let previousLanePriority; try { const isSync = true; const queue = syncQueue; - setCurrentUpdateLanePriority(SyncLanePriority); + if (enableSetUpdateLanePriority) { + previousLanePriority = getCurrentUpdateLanePriority(); + setCurrentUpdateLanePriority(SyncLanePriority); + } runWithPriority(ImmediatePriority, () => { for (; i < queue.length; i++) { let callback = queue[i]; @@ -202,7 +208,9 @@ function flushSyncCallbackQueueImpl() { ); throw error; } finally { - setCurrentUpdateLanePriority(previousLanePriority); + if (enableSetUpdateLanePriority && previousLanePriority != null) { + setCurrentUpdateLanePriority(previousLanePriority); + } isFlushingSyncQueue = false; } } diff --git a/packages/shared/ReactFeatureFlags.js b/packages/shared/ReactFeatureFlags.js index e0c38e9baaaf4..5f53f0cd2df08 100644 --- a/packages/shared/ReactFeatureFlags.js +++ b/packages/shared/ReactFeatureFlags.js @@ -128,3 +128,4 @@ export const deferRenderPhaseUpdateToNextBatch = true; // Replacement for runWithPriority in React internals. export const decoupleUpdatePriorityFromScheduler = false; +export const enableSetUpdateLanePriority = false; diff --git a/packages/shared/forks/ReactFeatureFlags.native-fb.js b/packages/shared/forks/ReactFeatureFlags.native-fb.js index 14180245136c3..4ee5f2374db89 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-fb.js +++ b/packages/shared/forks/ReactFeatureFlags.native-fb.js @@ -49,6 +49,7 @@ export const enableFilterEmptyStringAttributesDOM = false; export const enableNewReconciler = false; export const deferRenderPhaseUpdateToNextBatch = true; export const decoupleUpdatePriorityFromScheduler = false; +export const enableSetUpdateLanePriority = false; // Flow magic to verify the exports of this file match the original version. // eslint-disable-next-line no-unused-vars diff --git a/packages/shared/forks/ReactFeatureFlags.native-oss.js b/packages/shared/forks/ReactFeatureFlags.native-oss.js index e1f4100fdaaa5..ac329992e5f9e 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-oss.js +++ b/packages/shared/forks/ReactFeatureFlags.native-oss.js @@ -48,6 +48,7 @@ export const enableFilterEmptyStringAttributesDOM = false; export const enableNewReconciler = false; export const deferRenderPhaseUpdateToNextBatch = true; export const decoupleUpdatePriorityFromScheduler = false; +export const enableSetUpdateLanePriority = false; // Flow magic to verify the exports of this file match the original version. // eslint-disable-next-line no-unused-vars diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.js index 2c94f623ef3aa..1dc60bc2c1694 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.js @@ -48,6 +48,7 @@ export const enableFilterEmptyStringAttributesDOM = false; export const enableNewReconciler = false; export const deferRenderPhaseUpdateToNextBatch = true; export const decoupleUpdatePriorityFromScheduler = false; +export const enableSetUpdateLanePriority = false; // Flow magic to verify the exports of this file match the original version. // eslint-disable-next-line no-unused-vars diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js index eeb6866fc968f..d5a36d9fc529f 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js @@ -48,6 +48,7 @@ export const enableFilterEmptyStringAttributesDOM = false; export const enableNewReconciler = false; export const deferRenderPhaseUpdateToNextBatch = true; export const decoupleUpdatePriorityFromScheduler = false; +export const enableSetUpdateLanePriority = true; // Flow magic to verify the exports of this file match the original version. // eslint-disable-next-line no-unused-vars diff --git a/packages/shared/forks/ReactFeatureFlags.testing.js b/packages/shared/forks/ReactFeatureFlags.testing.js index 56e3f0284d9ef..a5be09f47c1df 100644 --- a/packages/shared/forks/ReactFeatureFlags.testing.js +++ b/packages/shared/forks/ReactFeatureFlags.testing.js @@ -48,6 +48,7 @@ export const enableFilterEmptyStringAttributesDOM = false; export const enableNewReconciler = false; export const deferRenderPhaseUpdateToNextBatch = true; export const decoupleUpdatePriorityFromScheduler = false; +export const enableSetUpdateLanePriority = true; // Flow magic to verify the exports of this file match the original version. // eslint-disable-next-line no-unused-vars diff --git a/packages/shared/forks/ReactFeatureFlags.testing.www.js b/packages/shared/forks/ReactFeatureFlags.testing.www.js index 414f5db9b0b6d..0b699cc55e81a 100644 --- a/packages/shared/forks/ReactFeatureFlags.testing.www.js +++ b/packages/shared/forks/ReactFeatureFlags.testing.www.js @@ -48,6 +48,7 @@ export const enableFilterEmptyStringAttributesDOM = false; export const enableNewReconciler = false; export const deferRenderPhaseUpdateToNextBatch = true; export const decoupleUpdatePriorityFromScheduler = false; +export const enableSetUpdateLanePriority = true; // Flow magic to verify the exports of this file match the original version. // eslint-disable-next-line no-unused-vars diff --git a/packages/shared/forks/ReactFeatureFlags.www-dynamic.js b/packages/shared/forks/ReactFeatureFlags.www-dynamic.js index 201a40fdbfa5b..472c9b524e62c 100644 --- a/packages/shared/forks/ReactFeatureFlags.www-dynamic.js +++ b/packages/shared/forks/ReactFeatureFlags.www-dynamic.js @@ -18,6 +18,7 @@ export const disableInputAttributeSyncing = __VARIANT__; export const enableFilterEmptyStringAttributesDOM = __VARIANT__; export const enableLegacyFBSupport = __VARIANT__; export const decoupleUpdatePriorityFromScheduler = __VARIANT__; +export const enableSetUpdateLanePriority = __VARIANT__; // Enable this flag to help with concurrent mode debugging. // It logs information to the console about React scheduling, rendering, and commit phases. diff --git a/packages/shared/forks/ReactFeatureFlags.www.js b/packages/shared/forks/ReactFeatureFlags.www.js index 6f0d031aff517..0865560bd0b2e 100644 --- a/packages/shared/forks/ReactFeatureFlags.www.js +++ b/packages/shared/forks/ReactFeatureFlags.www.js @@ -77,6 +77,8 @@ export const disableTextareaChildren = __EXPERIMENTAL__; export const warnUnstableRenderSubtreeIntoContainer = false; +export const enableSetUpdateLanePriority = true; + // Enable forked reconciler. Piggy-backing on the "variant" global so that we // don't have to add another test dimension. The build system will compile this // to the correct value. From 287a1f031054c3f18324eb5bf8eb38cf2cb4fb17 Mon Sep 17 00:00:00 2001 From: Rick Hanlon Date: Wed, 5 Aug 2020 21:08:17 -0400 Subject: [PATCH 2/4] Remove second feature flag --- .../DeprecatedDOMEventResponderSystem.js | 4 +-- .../src/events/ReactDOMEventListener.js | 4 +-- .../src/ReactFiberHooks.new.js | 8 +++--- .../src/ReactFiberHooks.old.js | 8 +++--- .../src/ReactFiberWorkLoop.new.js | 27 +++++++++---------- .../src/ReactFiberWorkLoop.old.js | 27 +++++++++---------- .../src/SchedulerWithReactIntegration.new.js | 6 ++--- .../src/SchedulerWithReactIntegration.old.js | 6 ++--- packages/shared/ReactFeatureFlags.js | 1 - .../forks/ReactFeatureFlags.native-fb.js | 1 - .../forks/ReactFeatureFlags.native-oss.js | 1 - .../forks/ReactFeatureFlags.test-renderer.js | 1 - .../ReactFeatureFlags.test-renderer.www.js | 1 - .../shared/forks/ReactFeatureFlags.testing.js | 1 - .../forks/ReactFeatureFlags.testing.www.js | 1 - .../forks/ReactFeatureFlags.www-dynamic.js | 1 - .../shared/forks/ReactFeatureFlags.www.js | 2 -- 17 files changed, 44 insertions(+), 56 deletions(-) diff --git a/packages/react-dom/src/events/DeprecatedDOMEventResponderSystem.js b/packages/react-dom/src/events/DeprecatedDOMEventResponderSystem.js index 29ee23a21e73f..18668ba3fa666 100644 --- a/packages/react-dom/src/events/DeprecatedDOMEventResponderSystem.js +++ b/packages/react-dom/src/events/DeprecatedDOMEventResponderSystem.js @@ -35,7 +35,7 @@ import { import type {Fiber} from 'react-reconciler/src/ReactInternalTypes'; import { enableDeprecatedFlareAPI, - enableSetUpdateLanePriority, + decoupleUpdatePriorityFromScheduler, } from 'shared/ReactFeatureFlags'; import invariant from 'shared/invariant'; @@ -111,7 +111,7 @@ const eventResponderContext: ReactDOMResponderContext = { break; } case UserBlockingEvent: { - if (enableSetUpdateLanePriority) { + if (decoupleUpdatePriorityFromScheduler) { // TODO: Double wrapping is necessary while we decouple Scheduler priority. const previousPriority = getCurrentUpdateLanePriority(); try { diff --git a/packages/react-dom/src/events/ReactDOMEventListener.js b/packages/react-dom/src/events/ReactDOMEventListener.js index 46c053ee3a375..e8e4fc641f791 100644 --- a/packages/react-dom/src/events/ReactDOMEventListener.js +++ b/packages/react-dom/src/events/ReactDOMEventListener.js @@ -44,7 +44,7 @@ import {getClosestInstanceFromNode} from '../client/ReactDOMComponentTree'; import { enableDeprecatedFlareAPI, enableLegacyFBSupport, - enableSetUpdateLanePriority, + decoupleUpdatePriorityFromScheduler, } from 'shared/ReactFeatureFlags'; import { UserBlockingEvent, @@ -154,7 +154,7 @@ function dispatchUserBlockingUpdate( container, nativeEvent, ) { - if (enableSetUpdateLanePriority) { + if (decoupleUpdatePriorityFromScheduler) { const previousPriority = getCurrentUpdateLanePriority(); try { // TODO: Double wrapping is necessary while we decouple Scheduler priority. diff --git a/packages/react-reconciler/src/ReactFiberHooks.new.js b/packages/react-reconciler/src/ReactFiberHooks.new.js index 6cbe2440d329d..6406801bfd0b0 100644 --- a/packages/react-reconciler/src/ReactFiberHooks.new.js +++ b/packages/react-reconciler/src/ReactFiberHooks.new.js @@ -28,7 +28,7 @@ import { enableDebugTracing, enableSchedulingProfiler, enableNewReconciler, - enableSetUpdateLanePriority, + decoupleUpdatePriorityFromScheduler, } from 'shared/ReactFeatureFlags'; import {NoMode, BlockingMode, DebugTracingMode} from './ReactTypeOfMode'; @@ -1511,7 +1511,7 @@ function rerenderDeferredValue( function startTransition(setPending, config, callback) { const priorityLevel = getCurrentPriorityLevel(); let previousLanePriority; - if (enableSetUpdateLanePriority) { + if (decoupleUpdatePriorityFromScheduler) { previousLanePriority = getCurrentUpdateLanePriority(); setCurrentUpdateLanePriority( higherLanePriority(previousLanePriority, InputContinuousLanePriority), @@ -1524,7 +1524,7 @@ function startTransition(setPending, config, callback) { }, ); - if (enableSetUpdateLanePriority) { + if (decoupleUpdatePriorityFromScheduler) { // If there's no SuspenseConfig set, we'll use the DefaultLanePriority for this transition. setCurrentUpdateLanePriority(DefaultLanePriority); } @@ -1538,7 +1538,7 @@ function startTransition(setPending, config, callback) { setPending(false); callback(); } finally { - if (enableSetUpdateLanePriority && previousLanePriority != null) { + if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { setCurrentUpdateLanePriority(previousLanePriority); } ReactCurrentBatchConfig.suspense = previousConfig; diff --git a/packages/react-reconciler/src/ReactFiberHooks.old.js b/packages/react-reconciler/src/ReactFiberHooks.old.js index 3f73ab1cf9c43..62a4fdc59d703 100644 --- a/packages/react-reconciler/src/ReactFiberHooks.old.js +++ b/packages/react-reconciler/src/ReactFiberHooks.old.js @@ -28,7 +28,7 @@ import { enableDebugTracing, enableSchedulingProfiler, enableNewReconciler, - enableSetUpdateLanePriority, + decoupleUpdatePriorityFromScheduler, } from 'shared/ReactFeatureFlags'; import {NoMode, BlockingMode, DebugTracingMode} from './ReactTypeOfMode'; @@ -1511,7 +1511,7 @@ function rerenderDeferredValue( function startTransition(setPending, config, callback) { const priorityLevel = getCurrentPriorityLevel(); let previousLanePriority; - if (enableSetUpdateLanePriority) { + if (decoupleUpdatePriorityFromScheduler) { previousLanePriority = getCurrentUpdateLanePriority(); setCurrentUpdateLanePriority( higherLanePriority(previousLanePriority, InputContinuousLanePriority), @@ -1524,7 +1524,7 @@ function startTransition(setPending, config, callback) { }, ); - if (enableSetUpdateLanePriority) { + if (decoupleUpdatePriorityFromScheduler) { // If there's no SuspenseConfig set, we'll use the DefaultLanePriority for this transition. setCurrentUpdateLanePriority(DefaultLanePriority); } @@ -1538,7 +1538,7 @@ function startTransition(setPending, config, callback) { setPending(false); callback(); } finally { - if (enableSetUpdateLanePriority && previousLanePriority != null) { + if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { setCurrentUpdateLanePriority(previousLanePriority); } ReactCurrentBatchConfig.suspense = previousConfig; diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js index 81b11272b67d1..38bb7b8d60137 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js @@ -30,7 +30,6 @@ import { enableDebugTracing, enableSchedulingProfiler, enableScopeAPI, - enableSetUpdateLanePriority, } from 'shared/ReactFeatureFlags'; import ReactSharedInternals from 'shared/ReactSharedInternals'; import invariant from 'shared/invariant'; @@ -478,7 +477,7 @@ export function requestUpdateLane( schedulerPriority, ); - if (enableSetUpdateLanePriority && decoupleUpdatePriorityFromScheduler) { + if (decoupleUpdatePriorityFromScheduler) { // In the new strategy, we will track the current update lane priority // inside React and use that priority to select a lane for this update. // For now, we're just logging when they're different so we can assess. @@ -1145,13 +1144,13 @@ export function flushDiscreteUpdates() { export function deferredUpdates(fn: () => A): A { let previousLanePriority; try { - if (enableSetUpdateLanePriority) { + if (decoupleUpdatePriorityFromScheduler) { previousLanePriority = getCurrentUpdateLanePriority(); setCurrentUpdateLanePriority(DefaultLanePriority); } return runWithPriority(NormalSchedulerPriority, fn); } finally { - if (enableSetUpdateLanePriority && previousLanePriority != null) { + if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { setCurrentUpdateLanePriority(previousLanePriority); } } @@ -1211,7 +1210,7 @@ export function discreteUpdates( executionContext |= DiscreteEventContext; let previousLanePriority; try { - if (enableSetUpdateLanePriority) { + if (decoupleUpdatePriorityFromScheduler) { previousLanePriority = getCurrentUpdateLanePriority(); setCurrentUpdateLanePriority(InputDiscreteLanePriority); } @@ -1221,7 +1220,7 @@ export function discreteUpdates( fn.bind(null, a, b, c, d), ); } finally { - if (enableSetUpdateLanePriority && previousLanePriority != null) { + if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { setCurrentUpdateLanePriority(previousLanePriority); } executionContext = prevExecutionContext; @@ -1262,7 +1261,7 @@ export function flushSync(fn: A => R, a: A): R { executionContext |= BatchedContext; let previousLanePriority; try { - if (enableSetUpdateLanePriority) { + if (decoupleUpdatePriorityFromScheduler) { previousLanePriority = getCurrentUpdateLanePriority(); setCurrentUpdateLanePriority(SyncLanePriority); } @@ -1272,7 +1271,7 @@ export function flushSync(fn: A => R, a: A): R { return (undefined: $FlowFixMe); } } finally { - if (enableSetUpdateLanePriority && previousLanePriority != null) { + if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { setCurrentUpdateLanePriority(previousLanePriority); } executionContext = prevExecutionContext; @@ -1288,13 +1287,13 @@ export function flushControlled(fn: () => mixed): void { executionContext |= BatchedContext; let previousLanePriority; try { - if (enableSetUpdateLanePriority) { + if (decoupleUpdatePriorityFromScheduler) { previousLanePriority = getCurrentUpdateLanePriority(); setCurrentUpdateLanePriority(SyncLanePriority); } runWithPriority(ImmediateSchedulerPriority, fn); } finally { - if (enableSetUpdateLanePriority && previousLanePriority != null) { + if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { setCurrentUpdateLanePriority(previousLanePriority); } executionContext = prevExecutionContext; @@ -2111,7 +2110,7 @@ function commitRootImpl(root, renderPriorityLevel) { if (firstEffect !== null) { let previousLanePriority; - if (enableSetUpdateLanePriority) { + if (decoupleUpdatePriorityFromScheduler) { previousLanePriority = getCurrentUpdateLanePriority(); setCurrentUpdateLanePriority(SyncLanePriority); } @@ -2191,7 +2190,7 @@ function commitRootImpl(root, renderPriorityLevel) { } executionContext = prevExecutionContext; - if (enableSetUpdateLanePriority && previousLanePriority != null) { + if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { // Reset the priority to the previous non-sync value. setCurrentUpdateLanePriority(previousLanePriority); } @@ -2634,7 +2633,7 @@ export function flushPassiveEffects() { pendingPassiveEffectsRenderPriority = NoSchedulerPriority; let previousLanePriority; try { - if (enableSetUpdateLanePriority) { + if (decoupleUpdatePriorityFromScheduler) { previousLanePriority = getCurrentUpdateLanePriority(); setCurrentUpdateLanePriority( schedulerPriorityToLanePriority(priorityLevel), @@ -2642,7 +2641,7 @@ export function flushPassiveEffects() { } return runWithPriority(priorityLevel, flushPassiveEffectsImpl); } finally { - if (enableSetUpdateLanePriority && previousLanePriority != null) { + if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { setCurrentUpdateLanePriority(previousLanePriority); } } diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js index 1f8f1647c92a0..0db6dc08e0810 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js @@ -30,7 +30,6 @@ import { enableDebugTracing, enableSchedulingProfiler, enableScopeAPI, - enableSetUpdateLanePriority, } from 'shared/ReactFeatureFlags'; import ReactSharedInternals from 'shared/ReactSharedInternals'; import invariant from 'shared/invariant'; @@ -471,7 +470,7 @@ export function requestUpdateLane( schedulerPriority, ); - if (enableSetUpdateLanePriority && decoupleUpdatePriorityFromScheduler) { + if (decoupleUpdatePriorityFromScheduler) { // In the new strategy, we will track the current update lane priority // inside React and use that priority to select a lane for this update. // For now, we're just logging when they're different so we can assess. @@ -1138,13 +1137,13 @@ export function flushDiscreteUpdates() { export function deferredUpdates(fn: () => A): A { let previousLanePriority; try { - if (enableSetUpdateLanePriority) { + if (decoupleUpdatePriorityFromScheduler) { previousLanePriority = getCurrentUpdateLanePriority(); setCurrentUpdateLanePriority(DefaultLanePriority); } return runWithPriority(NormalSchedulerPriority, fn); } finally { - if (enableSetUpdateLanePriority && previousLanePriority != null) { + if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { setCurrentUpdateLanePriority(previousLanePriority); } } @@ -1204,7 +1203,7 @@ export function discreteUpdates( executionContext |= DiscreteEventContext; let previousLanePriority; try { - if (enableSetUpdateLanePriority) { + if (decoupleUpdatePriorityFromScheduler) { previousLanePriority = getCurrentUpdateLanePriority(); setCurrentUpdateLanePriority(InputDiscreteLanePriority); } @@ -1214,7 +1213,7 @@ export function discreteUpdates( fn.bind(null, a, b, c, d), ); } finally { - if (enableSetUpdateLanePriority && previousLanePriority != null) { + if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { setCurrentUpdateLanePriority(previousLanePriority); } executionContext = prevExecutionContext; @@ -1255,7 +1254,7 @@ export function flushSync(fn: A => R, a: A): R { executionContext |= BatchedContext; let previousLanePriority; try { - if (enableSetUpdateLanePriority) { + if (decoupleUpdatePriorityFromScheduler) { previousLanePriority = getCurrentUpdateLanePriority(); setCurrentUpdateLanePriority(SyncLanePriority); } @@ -1265,7 +1264,7 @@ export function flushSync(fn: A => R, a: A): R { return (undefined: $FlowFixMe); } } finally { - if (enableSetUpdateLanePriority && previousLanePriority != null) { + if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { setCurrentUpdateLanePriority(previousLanePriority); } executionContext = prevExecutionContext; @@ -1281,13 +1280,13 @@ export function flushControlled(fn: () => mixed): void { executionContext |= BatchedContext; let previousLanePriority; try { - if (enableSetUpdateLanePriority) { + if (decoupleUpdatePriorityFromScheduler) { previousLanePriority = getCurrentUpdateLanePriority(); setCurrentUpdateLanePriority(SyncLanePriority); } runWithPriority(ImmediateSchedulerPriority, fn); } finally { - if (enableSetUpdateLanePriority && previousLanePriority != null) { + if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { setCurrentUpdateLanePriority(previousLanePriority); } executionContext = prevExecutionContext; @@ -2029,7 +2028,7 @@ function commitRootImpl(root, renderPriorityLevel) { if (firstEffect !== null) { let previousLanePriority; - if (enableSetUpdateLanePriority) { + if (decoupleUpdatePriorityFromScheduler) { previousLanePriority = getCurrentUpdateLanePriority(); setCurrentUpdateLanePriority(SyncLanePriority); } @@ -2155,7 +2154,7 @@ function commitRootImpl(root, renderPriorityLevel) { } executionContext = prevExecutionContext; - if (enableSetUpdateLanePriority && previousLanePriority != null) { + if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { // Reset the priority to the previous non-sync value. setCurrentUpdateLanePriority(previousLanePriority); } @@ -2478,7 +2477,7 @@ export function flushPassiveEffects() { pendingPassiveEffectsRenderPriority = NoSchedulerPriority; let previousLanePriority; try { - if (enableSetUpdateLanePriority) { + if (decoupleUpdatePriorityFromScheduler) { previousLanePriority = getCurrentUpdateLanePriority(); setCurrentUpdateLanePriority( schedulerPriorityToLanePriority(priorityLevel), @@ -2486,7 +2485,7 @@ export function flushPassiveEffects() { } return runWithPriority(priorityLevel, flushPassiveEffectsImpl); } finally { - if (enableSetUpdateLanePriority && previousLanePriority != null) { + if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { setCurrentUpdateLanePriority(previousLanePriority); } } diff --git a/packages/react-reconciler/src/SchedulerWithReactIntegration.new.js b/packages/react-reconciler/src/SchedulerWithReactIntegration.new.js index a865009361866..242baad6e6c0c 100644 --- a/packages/react-reconciler/src/SchedulerWithReactIntegration.new.js +++ b/packages/react-reconciler/src/SchedulerWithReactIntegration.new.js @@ -15,7 +15,7 @@ import * as Scheduler from 'scheduler'; import {__interactionsRef} from 'scheduler/tracing'; import { enableSchedulerTracing, - enableSetUpdateLanePriority, + decoupleUpdatePriorityFromScheduler, } from 'shared/ReactFeatureFlags'; import invariant from 'shared/invariant'; import { @@ -183,7 +183,7 @@ function flushSyncCallbackQueueImpl() { try { const isSync = true; const queue = syncQueue; - if (enableSetUpdateLanePriority) { + if (decoupleUpdatePriorityFromScheduler) { previousLanePriority = getCurrentUpdateLanePriority(); setCurrentUpdateLanePriority(SyncLanePriority); } @@ -208,7 +208,7 @@ function flushSyncCallbackQueueImpl() { ); throw error; } finally { - if (enableSetUpdateLanePriority && previousLanePriority != null) { + if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { setCurrentUpdateLanePriority(previousLanePriority); } isFlushingSyncQueue = false; diff --git a/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js b/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js index a865009361866..242baad6e6c0c 100644 --- a/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js +++ b/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js @@ -15,7 +15,7 @@ import * as Scheduler from 'scheduler'; import {__interactionsRef} from 'scheduler/tracing'; import { enableSchedulerTracing, - enableSetUpdateLanePriority, + decoupleUpdatePriorityFromScheduler, } from 'shared/ReactFeatureFlags'; import invariant from 'shared/invariant'; import { @@ -183,7 +183,7 @@ function flushSyncCallbackQueueImpl() { try { const isSync = true; const queue = syncQueue; - if (enableSetUpdateLanePriority) { + if (decoupleUpdatePriorityFromScheduler) { previousLanePriority = getCurrentUpdateLanePriority(); setCurrentUpdateLanePriority(SyncLanePriority); } @@ -208,7 +208,7 @@ function flushSyncCallbackQueueImpl() { ); throw error; } finally { - if (enableSetUpdateLanePriority && previousLanePriority != null) { + if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { setCurrentUpdateLanePriority(previousLanePriority); } isFlushingSyncQueue = false; diff --git a/packages/shared/ReactFeatureFlags.js b/packages/shared/ReactFeatureFlags.js index 5f53f0cd2df08..e0c38e9baaaf4 100644 --- a/packages/shared/ReactFeatureFlags.js +++ b/packages/shared/ReactFeatureFlags.js @@ -128,4 +128,3 @@ export const deferRenderPhaseUpdateToNextBatch = true; // Replacement for runWithPriority in React internals. export const decoupleUpdatePriorityFromScheduler = false; -export const enableSetUpdateLanePriority = false; diff --git a/packages/shared/forks/ReactFeatureFlags.native-fb.js b/packages/shared/forks/ReactFeatureFlags.native-fb.js index 4ee5f2374db89..14180245136c3 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-fb.js +++ b/packages/shared/forks/ReactFeatureFlags.native-fb.js @@ -49,7 +49,6 @@ export const enableFilterEmptyStringAttributesDOM = false; export const enableNewReconciler = false; export const deferRenderPhaseUpdateToNextBatch = true; export const decoupleUpdatePriorityFromScheduler = false; -export const enableSetUpdateLanePriority = false; // Flow magic to verify the exports of this file match the original version. // eslint-disable-next-line no-unused-vars diff --git a/packages/shared/forks/ReactFeatureFlags.native-oss.js b/packages/shared/forks/ReactFeatureFlags.native-oss.js index ac329992e5f9e..e1f4100fdaaa5 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-oss.js +++ b/packages/shared/forks/ReactFeatureFlags.native-oss.js @@ -48,7 +48,6 @@ export const enableFilterEmptyStringAttributesDOM = false; export const enableNewReconciler = false; export const deferRenderPhaseUpdateToNextBatch = true; export const decoupleUpdatePriorityFromScheduler = false; -export const enableSetUpdateLanePriority = false; // Flow magic to verify the exports of this file match the original version. // eslint-disable-next-line no-unused-vars diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.js index 1dc60bc2c1694..2c94f623ef3aa 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.js @@ -48,7 +48,6 @@ export const enableFilterEmptyStringAttributesDOM = false; export const enableNewReconciler = false; export const deferRenderPhaseUpdateToNextBatch = true; export const decoupleUpdatePriorityFromScheduler = false; -export const enableSetUpdateLanePriority = false; // Flow magic to verify the exports of this file match the original version. // eslint-disable-next-line no-unused-vars diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js index d5a36d9fc529f..eeb6866fc968f 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js @@ -48,7 +48,6 @@ export const enableFilterEmptyStringAttributesDOM = false; export const enableNewReconciler = false; export const deferRenderPhaseUpdateToNextBatch = true; export const decoupleUpdatePriorityFromScheduler = false; -export const enableSetUpdateLanePriority = true; // Flow magic to verify the exports of this file match the original version. // eslint-disable-next-line no-unused-vars diff --git a/packages/shared/forks/ReactFeatureFlags.testing.js b/packages/shared/forks/ReactFeatureFlags.testing.js index a5be09f47c1df..56e3f0284d9ef 100644 --- a/packages/shared/forks/ReactFeatureFlags.testing.js +++ b/packages/shared/forks/ReactFeatureFlags.testing.js @@ -48,7 +48,6 @@ export const enableFilterEmptyStringAttributesDOM = false; export const enableNewReconciler = false; export const deferRenderPhaseUpdateToNextBatch = true; export const decoupleUpdatePriorityFromScheduler = false; -export const enableSetUpdateLanePriority = true; // Flow magic to verify the exports of this file match the original version. // eslint-disable-next-line no-unused-vars diff --git a/packages/shared/forks/ReactFeatureFlags.testing.www.js b/packages/shared/forks/ReactFeatureFlags.testing.www.js index 0b699cc55e81a..414f5db9b0b6d 100644 --- a/packages/shared/forks/ReactFeatureFlags.testing.www.js +++ b/packages/shared/forks/ReactFeatureFlags.testing.www.js @@ -48,7 +48,6 @@ export const enableFilterEmptyStringAttributesDOM = false; export const enableNewReconciler = false; export const deferRenderPhaseUpdateToNextBatch = true; export const decoupleUpdatePriorityFromScheduler = false; -export const enableSetUpdateLanePriority = true; // Flow magic to verify the exports of this file match the original version. // eslint-disable-next-line no-unused-vars diff --git a/packages/shared/forks/ReactFeatureFlags.www-dynamic.js b/packages/shared/forks/ReactFeatureFlags.www-dynamic.js index 472c9b524e62c..201a40fdbfa5b 100644 --- a/packages/shared/forks/ReactFeatureFlags.www-dynamic.js +++ b/packages/shared/forks/ReactFeatureFlags.www-dynamic.js @@ -18,7 +18,6 @@ export const disableInputAttributeSyncing = __VARIANT__; export const enableFilterEmptyStringAttributesDOM = __VARIANT__; export const enableLegacyFBSupport = __VARIANT__; export const decoupleUpdatePriorityFromScheduler = __VARIANT__; -export const enableSetUpdateLanePriority = __VARIANT__; // Enable this flag to help with concurrent mode debugging. // It logs information to the console about React scheduling, rendering, and commit phases. diff --git a/packages/shared/forks/ReactFeatureFlags.www.js b/packages/shared/forks/ReactFeatureFlags.www.js index 0865560bd0b2e..6f0d031aff517 100644 --- a/packages/shared/forks/ReactFeatureFlags.www.js +++ b/packages/shared/forks/ReactFeatureFlags.www.js @@ -77,8 +77,6 @@ export const disableTextareaChildren = __EXPERIMENTAL__; export const warnUnstableRenderSubtreeIntoContainer = false; -export const enableSetUpdateLanePriority = true; - // Enable forked reconciler. Piggy-backing on the "variant" global so that we // don't have to add another test dimension. The build system will compile this // to the correct value. From baf12b80d5f1c70e33a9fbc00a567f56b12d8800 Mon Sep 17 00:00:00 2001 From: Rick Hanlon Date: Wed, 5 Aug 2020 21:36:20 -0400 Subject: [PATCH 3/4] Refactor feature flag locations --- .../src/ReactFiberHooks.new.js | 75 ++++++--- .../src/ReactFiberHooks.old.js | 75 ++++++--- .../src/ReactFiberWorkLoop.new.js | 150 +++++++++++------- .../src/ReactFiberWorkLoop.old.js | 150 +++++++++++------- .../src/SchedulerWithReactIntegration.new.js | 40 ++++- .../src/SchedulerWithReactIntegration.old.js | 40 ++++- 6 files changed, 340 insertions(+), 190 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberHooks.new.js b/packages/react-reconciler/src/ReactFiberHooks.new.js index 6406801bfd0b0..6adf46a4fb6e3 100644 --- a/packages/react-reconciler/src/ReactFiberHooks.new.js +++ b/packages/react-reconciler/src/ReactFiberHooks.new.js @@ -1510,41 +1510,64 @@ function rerenderDeferredValue( function startTransition(setPending, config, callback) { const priorityLevel = getCurrentPriorityLevel(); - let previousLanePriority; if (decoupleUpdatePriorityFromScheduler) { - previousLanePriority = getCurrentUpdateLanePriority(); + const previousLanePriority = getCurrentUpdateLanePriority(); setCurrentUpdateLanePriority( higherLanePriority(previousLanePriority, InputContinuousLanePriority), ); - } - runWithPriority( - priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel, - () => { - setPending(true); - }, - ); - if (decoupleUpdatePriorityFromScheduler) { + runWithPriority( + priorityLevel < UserBlockingPriority + ? UserBlockingPriority + : priorityLevel, + () => { + setPending(true); + }, + ); + // If there's no SuspenseConfig set, we'll use the DefaultLanePriority for this transition. setCurrentUpdateLanePriority(DefaultLanePriority); - } - runWithPriority( - priorityLevel > NormalPriority ? NormalPriority : priorityLevel, - () => { - const previousConfig = ReactCurrentBatchConfig.suspense; - ReactCurrentBatchConfig.suspense = config === undefined ? null : config; - try { - setPending(false); - callback(); - } finally { - if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { - setCurrentUpdateLanePriority(previousLanePriority); + runWithPriority( + priorityLevel > NormalPriority ? NormalPriority : priorityLevel, + () => { + const previousConfig = ReactCurrentBatchConfig.suspense; + ReactCurrentBatchConfig.suspense = config === undefined ? null : config; + try { + setPending(false); + callback(); + } finally { + if (decoupleUpdatePriorityFromScheduler) { + setCurrentUpdateLanePriority(previousLanePriority); + } + ReactCurrentBatchConfig.suspense = previousConfig; } - ReactCurrentBatchConfig.suspense = previousConfig; - } - }, - ); + }, + ); + } else { + runWithPriority( + priorityLevel < UserBlockingPriority + ? UserBlockingPriority + : priorityLevel, + () => { + setPending(true); + }, + ); + + runWithPriority( + priorityLevel > NormalPriority ? NormalPriority : priorityLevel, + () => { + const previousConfig = ReactCurrentBatchConfig.suspense; + ReactCurrentBatchConfig.suspense = config === undefined ? null : config; + try { + setPending(false); + callback(); + } finally { + ReactCurrentBatchConfig.suspense = previousConfig; + } + }, + ); + } } function mountTransition( diff --git a/packages/react-reconciler/src/ReactFiberHooks.old.js b/packages/react-reconciler/src/ReactFiberHooks.old.js index 62a4fdc59d703..1a89cbba2f3fc 100644 --- a/packages/react-reconciler/src/ReactFiberHooks.old.js +++ b/packages/react-reconciler/src/ReactFiberHooks.old.js @@ -1510,41 +1510,64 @@ function rerenderDeferredValue( function startTransition(setPending, config, callback) { const priorityLevel = getCurrentPriorityLevel(); - let previousLanePriority; if (decoupleUpdatePriorityFromScheduler) { - previousLanePriority = getCurrentUpdateLanePriority(); + const previousLanePriority = getCurrentUpdateLanePriority(); setCurrentUpdateLanePriority( higherLanePriority(previousLanePriority, InputContinuousLanePriority), ); - } - runWithPriority( - priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel, - () => { - setPending(true); - }, - ); - if (decoupleUpdatePriorityFromScheduler) { + runWithPriority( + priorityLevel < UserBlockingPriority + ? UserBlockingPriority + : priorityLevel, + () => { + setPending(true); + }, + ); + // If there's no SuspenseConfig set, we'll use the DefaultLanePriority for this transition. setCurrentUpdateLanePriority(DefaultLanePriority); - } - runWithPriority( - priorityLevel > NormalPriority ? NormalPriority : priorityLevel, - () => { - const previousConfig = ReactCurrentBatchConfig.suspense; - ReactCurrentBatchConfig.suspense = config === undefined ? null : config; - try { - setPending(false); - callback(); - } finally { - if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { - setCurrentUpdateLanePriority(previousLanePriority); + runWithPriority( + priorityLevel > NormalPriority ? NormalPriority : priorityLevel, + () => { + const previousConfig = ReactCurrentBatchConfig.suspense; + ReactCurrentBatchConfig.suspense = config === undefined ? null : config; + try { + setPending(false); + callback(); + } finally { + if (decoupleUpdatePriorityFromScheduler) { + setCurrentUpdateLanePriority(previousLanePriority); + } + ReactCurrentBatchConfig.suspense = previousConfig; } - ReactCurrentBatchConfig.suspense = previousConfig; - } - }, - ); + }, + ); + } else { + runWithPriority( + priorityLevel < UserBlockingPriority + ? UserBlockingPriority + : priorityLevel, + () => { + setPending(true); + }, + ); + + runWithPriority( + priorityLevel > NormalPriority ? NormalPriority : priorityLevel, + () => { + const previousConfig = ReactCurrentBatchConfig.suspense; + ReactCurrentBatchConfig.suspense = config === undefined ? null : config; + try { + setPending(false); + callback(); + } finally { + ReactCurrentBatchConfig.suspense = previousConfig; + } + }, + ); + } } function mountTransition( diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js index 38bb7b8d60137..4c8e8fc4c24b9 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js @@ -1142,17 +1142,16 @@ export function flushDiscreteUpdates() { } export function deferredUpdates(fn: () => A): A { - let previousLanePriority; - try { - if (decoupleUpdatePriorityFromScheduler) { - previousLanePriority = getCurrentUpdateLanePriority(); + if (decoupleUpdatePriorityFromScheduler) { + const previousLanePriority = getCurrentUpdateLanePriority(); + try { setCurrentUpdateLanePriority(DefaultLanePriority); - } - return runWithPriority(NormalSchedulerPriority, fn); - } finally { - if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { + return runWithPriority(NormalSchedulerPriority, fn); + } finally { setCurrentUpdateLanePriority(previousLanePriority); } + } else { + return runWithPriority(NormalSchedulerPriority, fn); } } @@ -1208,25 +1207,35 @@ export function discreteUpdates( ): R { const prevExecutionContext = executionContext; executionContext |= DiscreteEventContext; - let previousLanePriority; - try { - if (decoupleUpdatePriorityFromScheduler) { - previousLanePriority = getCurrentUpdateLanePriority(); + + if (decoupleUpdatePriorityFromScheduler) { + const previousLanePriority = getCurrentUpdateLanePriority(); + try { setCurrentUpdateLanePriority(InputDiscreteLanePriority); - } - // Should this - return runWithPriority( - UserBlockingSchedulerPriority, - fn.bind(null, a, b, c, d), - ); - } finally { - if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { + return runWithPriority( + UserBlockingSchedulerPriority, + fn.bind(null, a, b, c, d), + ); + } finally { setCurrentUpdateLanePriority(previousLanePriority); + executionContext = prevExecutionContext; + if (executionContext === NoContext) { + // Flush the immediate callbacks that were scheduled during this batch + flushSyncCallbackQueue(); + } } - executionContext = prevExecutionContext; - if (executionContext === NoContext) { - // Flush the immediate callbacks that were scheduled during this batch - flushSyncCallbackQueue(); + } else { + try { + return runWithPriority( + UserBlockingSchedulerPriority, + fn.bind(null, a, b, c, d), + ); + } finally { + executionContext = prevExecutionContext; + if (executionContext === NoContext) { + // Flush the immediate callbacks that were scheduled during this batch + flushSyncCallbackQueue(); + } } } } @@ -1259,47 +1268,67 @@ export function flushSync(fn: A => R, a: A): R { return fn(a); } executionContext |= BatchedContext; - let previousLanePriority; - try { - if (decoupleUpdatePriorityFromScheduler) { - previousLanePriority = getCurrentUpdateLanePriority(); + + if (decoupleUpdatePriorityFromScheduler) { + const previousLanePriority = getCurrentUpdateLanePriority(); + try { setCurrentUpdateLanePriority(SyncLanePriority); - } - if (fn) { - return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a)); - } else { - return (undefined: $FlowFixMe); - } - } finally { - if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { + if (fn) { + return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a)); + } else { + return (undefined: $FlowFixMe); + } + } finally { 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 + // the stack. + flushSyncCallbackQueue(); + } + } else { + try { + if (fn) { + return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a)); + } else { + return (undefined: $FlowFixMe); + } + } finally { + executionContext = prevExecutionContext; + // Flush the immediate callbacks that were scheduled during this batch. + // Note that this will happen even if batchedUpdates is higher up + // the stack. + flushSyncCallbackQueue(); } - executionContext = prevExecutionContext; - // Flush the immediate callbacks that were scheduled during this batch. - // Note that this will happen even if batchedUpdates is higher up - // the stack. - flushSyncCallbackQueue(); } } export function flushControlled(fn: () => mixed): void { const prevExecutionContext = executionContext; executionContext |= BatchedContext; - let previousLanePriority; - try { - if (decoupleUpdatePriorityFromScheduler) { - previousLanePriority = getCurrentUpdateLanePriority(); + if (decoupleUpdatePriorityFromScheduler) { + const previousLanePriority = getCurrentUpdateLanePriority(); + try { setCurrentUpdateLanePriority(SyncLanePriority); - } - runWithPriority(ImmediateSchedulerPriority, fn); - } finally { - if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { + runWithPriority(ImmediateSchedulerPriority, fn); + } finally { setCurrentUpdateLanePriority(previousLanePriority); + + executionContext = prevExecutionContext; + if (executionContext === NoContext) { + // Flush the immediate callbacks that were scheduled during this batch + flushSyncCallbackQueue(); + } } - executionContext = prevExecutionContext; - if (executionContext === NoContext) { - // Flush the immediate callbacks that were scheduled during this batch - flushSyncCallbackQueue(); + } else { + try { + runWithPriority(ImmediateSchedulerPriority, fn); + } finally { + executionContext = prevExecutionContext; + if (executionContext === NoContext) { + // Flush the immediate callbacks that were scheduled during this batch + flushSyncCallbackQueue(); + } } } } @@ -2631,19 +2660,18 @@ export function flushPassiveEffects() { ? NormalSchedulerPriority : pendingPassiveEffectsRenderPriority; pendingPassiveEffectsRenderPriority = NoSchedulerPriority; - let previousLanePriority; - try { - if (decoupleUpdatePriorityFromScheduler) { - previousLanePriority = getCurrentUpdateLanePriority(); + if (decoupleUpdatePriorityFromScheduler) { + const previousLanePriority = getCurrentUpdateLanePriority(); + try { setCurrentUpdateLanePriority( schedulerPriorityToLanePriority(priorityLevel), ); - } - return runWithPriority(priorityLevel, flushPassiveEffectsImpl); - } finally { - if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { + return runWithPriority(priorityLevel, flushPassiveEffectsImpl); + } finally { setCurrentUpdateLanePriority(previousLanePriority); } + } else { + return runWithPriority(priorityLevel, flushPassiveEffectsImpl); } } } diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js index 0db6dc08e0810..1e5502d451855 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js @@ -1135,17 +1135,16 @@ export function flushDiscreteUpdates() { } export function deferredUpdates(fn: () => A): A { - let previousLanePriority; - try { - if (decoupleUpdatePriorityFromScheduler) { - previousLanePriority = getCurrentUpdateLanePriority(); + if (decoupleUpdatePriorityFromScheduler) { + const previousLanePriority = getCurrentUpdateLanePriority(); + try { setCurrentUpdateLanePriority(DefaultLanePriority); - } - return runWithPriority(NormalSchedulerPriority, fn); - } finally { - if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { + return runWithPriority(NormalSchedulerPriority, fn); + } finally { setCurrentUpdateLanePriority(previousLanePriority); } + } else { + return runWithPriority(NormalSchedulerPriority, fn); } } @@ -1201,25 +1200,35 @@ export function discreteUpdates( ): R { const prevExecutionContext = executionContext; executionContext |= DiscreteEventContext; - let previousLanePriority; - try { - if (decoupleUpdatePriorityFromScheduler) { - previousLanePriority = getCurrentUpdateLanePriority(); + + if (decoupleUpdatePriorityFromScheduler) { + const previousLanePriority = getCurrentUpdateLanePriority(); + try { setCurrentUpdateLanePriority(InputDiscreteLanePriority); - } - // Should this - return runWithPriority( - UserBlockingSchedulerPriority, - fn.bind(null, a, b, c, d), - ); - } finally { - if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { + return runWithPriority( + UserBlockingSchedulerPriority, + fn.bind(null, a, b, c, d), + ); + } finally { setCurrentUpdateLanePriority(previousLanePriority); + executionContext = prevExecutionContext; + if (executionContext === NoContext) { + // Flush the immediate callbacks that were scheduled during this batch + flushSyncCallbackQueue(); + } } - executionContext = prevExecutionContext; - if (executionContext === NoContext) { - // Flush the immediate callbacks that were scheduled during this batch - flushSyncCallbackQueue(); + } else { + try { + return runWithPriority( + UserBlockingSchedulerPriority, + fn.bind(null, a, b, c, d), + ); + } finally { + executionContext = prevExecutionContext; + if (executionContext === NoContext) { + // Flush the immediate callbacks that were scheduled during this batch + flushSyncCallbackQueue(); + } } } } @@ -1252,47 +1261,67 @@ export function flushSync(fn: A => R, a: A): R { return fn(a); } executionContext |= BatchedContext; - let previousLanePriority; - try { - if (decoupleUpdatePriorityFromScheduler) { - previousLanePriority = getCurrentUpdateLanePriority(); + + if (decoupleUpdatePriorityFromScheduler) { + const previousLanePriority = getCurrentUpdateLanePriority(); + try { setCurrentUpdateLanePriority(SyncLanePriority); - } - if (fn) { - return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a)); - } else { - return (undefined: $FlowFixMe); - } - } finally { - if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { + if (fn) { + return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a)); + } else { + return (undefined: $FlowFixMe); + } + } finally { 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 + // the stack. + flushSyncCallbackQueue(); + } + } else { + try { + if (fn) { + return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a)); + } else { + return (undefined: $FlowFixMe); + } + } finally { + executionContext = prevExecutionContext; + // Flush the immediate callbacks that were scheduled during this batch. + // Note that this will happen even if batchedUpdates is higher up + // the stack. + flushSyncCallbackQueue(); } - executionContext = prevExecutionContext; - // Flush the immediate callbacks that were scheduled during this batch. - // Note that this will happen even if batchedUpdates is higher up - // the stack. - flushSyncCallbackQueue(); } } export function flushControlled(fn: () => mixed): void { const prevExecutionContext = executionContext; executionContext |= BatchedContext; - let previousLanePriority; - try { - if (decoupleUpdatePriorityFromScheduler) { - previousLanePriority = getCurrentUpdateLanePriority(); + if (decoupleUpdatePriorityFromScheduler) { + const previousLanePriority = getCurrentUpdateLanePriority(); + try { setCurrentUpdateLanePriority(SyncLanePriority); - } - runWithPriority(ImmediateSchedulerPriority, fn); - } finally { - if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { + runWithPriority(ImmediateSchedulerPriority, fn); + } finally { setCurrentUpdateLanePriority(previousLanePriority); + + executionContext = prevExecutionContext; + if (executionContext === NoContext) { + // Flush the immediate callbacks that were scheduled during this batch + flushSyncCallbackQueue(); + } } - executionContext = prevExecutionContext; - if (executionContext === NoContext) { - // Flush the immediate callbacks that were scheduled during this batch - flushSyncCallbackQueue(); + } else { + try { + runWithPriority(ImmediateSchedulerPriority, fn); + } finally { + executionContext = prevExecutionContext; + if (executionContext === NoContext) { + // Flush the immediate callbacks that were scheduled during this batch + flushSyncCallbackQueue(); + } } } } @@ -2475,19 +2504,18 @@ export function flushPassiveEffects() { ? NormalSchedulerPriority : pendingPassiveEffectsRenderPriority; pendingPassiveEffectsRenderPriority = NoSchedulerPriority; - let previousLanePriority; - try { - if (decoupleUpdatePriorityFromScheduler) { - previousLanePriority = getCurrentUpdateLanePriority(); + if (decoupleUpdatePriorityFromScheduler) { + const previousLanePriority = getCurrentUpdateLanePriority(); + try { setCurrentUpdateLanePriority( schedulerPriorityToLanePriority(priorityLevel), ); - } - return runWithPriority(priorityLevel, flushPassiveEffectsImpl); - } finally { - if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { + return runWithPriority(priorityLevel, flushPassiveEffectsImpl); + } finally { setCurrentUpdateLanePriority(previousLanePriority); } + } else { + return runWithPriority(priorityLevel, flushPassiveEffectsImpl); } } } diff --git a/packages/react-reconciler/src/SchedulerWithReactIntegration.new.js b/packages/react-reconciler/src/SchedulerWithReactIntegration.new.js index 242baad6e6c0c..10eaa3f85ebe6 100644 --- a/packages/react-reconciler/src/SchedulerWithReactIntegration.new.js +++ b/packages/react-reconciler/src/SchedulerWithReactIntegration.new.js @@ -179,14 +179,41 @@ function flushSyncCallbackQueueImpl() { // Prevent re-entrancy. isFlushingSyncQueue = true; let i = 0; - let previousLanePriority; + if (decoupleUpdatePriorityFromScheduler) { + const previousLanePriority = getCurrentUpdateLanePriority(); + try { + const isSync = true; + const queue = syncQueue; + setCurrentUpdateLanePriority(SyncLanePriority); + runWithPriority(ImmediatePriority, () => { + for (; i < queue.length; i++) { + let callback = queue[i]; + do { + callback = callback(isSync); + } while (callback !== null); + } + }); + syncQueue = null; + } catch (error) { + // If something throws, leave the remaining callbacks on the queue. + if (syncQueue !== null) { + syncQueue = syncQueue.slice(i + 1); + } + // Resume flushing in the next tick + Scheduler_scheduleCallback( + Scheduler_ImmediatePriority, + flushSyncCallbackQueue, + ); + throw error; + } finally { + setCurrentUpdateLanePriority(previousLanePriority); + isFlushingSyncQueue = false; + } + } + try { const isSync = true; const queue = syncQueue; - if (decoupleUpdatePriorityFromScheduler) { - previousLanePriority = getCurrentUpdateLanePriority(); - setCurrentUpdateLanePriority(SyncLanePriority); - } runWithPriority(ImmediatePriority, () => { for (; i < queue.length; i++) { let callback = queue[i]; @@ -208,9 +235,6 @@ function flushSyncCallbackQueueImpl() { ); throw error; } finally { - if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { - setCurrentUpdateLanePriority(previousLanePriority); - } isFlushingSyncQueue = false; } } diff --git a/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js b/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js index 242baad6e6c0c..10eaa3f85ebe6 100644 --- a/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js +++ b/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js @@ -179,14 +179,41 @@ function flushSyncCallbackQueueImpl() { // Prevent re-entrancy. isFlushingSyncQueue = true; let i = 0; - let previousLanePriority; + if (decoupleUpdatePriorityFromScheduler) { + const previousLanePriority = getCurrentUpdateLanePriority(); + try { + const isSync = true; + const queue = syncQueue; + setCurrentUpdateLanePriority(SyncLanePriority); + runWithPriority(ImmediatePriority, () => { + for (; i < queue.length; i++) { + let callback = queue[i]; + do { + callback = callback(isSync); + } while (callback !== null); + } + }); + syncQueue = null; + } catch (error) { + // If something throws, leave the remaining callbacks on the queue. + if (syncQueue !== null) { + syncQueue = syncQueue.slice(i + 1); + } + // Resume flushing in the next tick + Scheduler_scheduleCallback( + Scheduler_ImmediatePriority, + flushSyncCallbackQueue, + ); + throw error; + } finally { + setCurrentUpdateLanePriority(previousLanePriority); + isFlushingSyncQueue = false; + } + } + try { const isSync = true; const queue = syncQueue; - if (decoupleUpdatePriorityFromScheduler) { - previousLanePriority = getCurrentUpdateLanePriority(); - setCurrentUpdateLanePriority(SyncLanePriority); - } runWithPriority(ImmediatePriority, () => { for (; i < queue.length; i++) { let callback = queue[i]; @@ -208,9 +235,6 @@ function flushSyncCallbackQueueImpl() { ); throw error; } finally { - if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) { - setCurrentUpdateLanePriority(previousLanePriority); - } isFlushingSyncQueue = false; } } From caceeca98e84ee2a38a221452989f902813bee79 Mon Sep 17 00:00:00 2001 From: Rick Hanlon Date: Wed, 5 Aug 2020 22:42:10 -0400 Subject: [PATCH 4/4] Add missing else --- .../src/SchedulerWithReactIntegration.new.js | 50 +++++++++---------- .../src/SchedulerWithReactIntegration.old.js | 50 +++++++++---------- 2 files changed, 50 insertions(+), 50 deletions(-) diff --git a/packages/react-reconciler/src/SchedulerWithReactIntegration.new.js b/packages/react-reconciler/src/SchedulerWithReactIntegration.new.js index 10eaa3f85ebe6..18e4ba82ab36c 100644 --- a/packages/react-reconciler/src/SchedulerWithReactIntegration.new.js +++ b/packages/react-reconciler/src/SchedulerWithReactIntegration.new.js @@ -209,33 +209,33 @@ function flushSyncCallbackQueueImpl() { setCurrentUpdateLanePriority(previousLanePriority); isFlushingSyncQueue = false; } - } - - try { - const isSync = true; - const queue = syncQueue; - runWithPriority(ImmediatePriority, () => { - for (; i < queue.length; i++) { - let callback = queue[i]; - do { - callback = callback(isSync); - } while (callback !== null); + } else { + try { + const isSync = true; + const queue = syncQueue; + runWithPriority(ImmediatePriority, () => { + for (; i < queue.length; i++) { + let callback = queue[i]; + do { + callback = callback(isSync); + } while (callback !== null); + } + }); + syncQueue = null; + } catch (error) { + // If something throws, leave the remaining callbacks on the queue. + if (syncQueue !== null) { + syncQueue = syncQueue.slice(i + 1); } - }); - syncQueue = null; - } catch (error) { - // If something throws, leave the remaining callbacks on the queue. - if (syncQueue !== null) { - syncQueue = syncQueue.slice(i + 1); + // Resume flushing in the next tick + Scheduler_scheduleCallback( + Scheduler_ImmediatePriority, + flushSyncCallbackQueue, + ); + throw error; + } finally { + isFlushingSyncQueue = false; } - // Resume flushing in the next tick - Scheduler_scheduleCallback( - Scheduler_ImmediatePriority, - flushSyncCallbackQueue, - ); - throw error; - } finally { - isFlushingSyncQueue = false; } } } diff --git a/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js b/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js index 10eaa3f85ebe6..18e4ba82ab36c 100644 --- a/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js +++ b/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js @@ -209,33 +209,33 @@ function flushSyncCallbackQueueImpl() { setCurrentUpdateLanePriority(previousLanePriority); isFlushingSyncQueue = false; } - } - - try { - const isSync = true; - const queue = syncQueue; - runWithPriority(ImmediatePriority, () => { - for (; i < queue.length; i++) { - let callback = queue[i]; - do { - callback = callback(isSync); - } while (callback !== null); + } else { + try { + const isSync = true; + const queue = syncQueue; + runWithPriority(ImmediatePriority, () => { + for (; i < queue.length; i++) { + let callback = queue[i]; + do { + callback = callback(isSync); + } while (callback !== null); + } + }); + syncQueue = null; + } catch (error) { + // If something throws, leave the remaining callbacks on the queue. + if (syncQueue !== null) { + syncQueue = syncQueue.slice(i + 1); } - }); - syncQueue = null; - } catch (error) { - // If something throws, leave the remaining callbacks on the queue. - if (syncQueue !== null) { - syncQueue = syncQueue.slice(i + 1); + // Resume flushing in the next tick + Scheduler_scheduleCallback( + Scheduler_ImmediatePriority, + flushSyncCallbackQueue, + ); + throw error; + } finally { + isFlushingSyncQueue = false; } - // Resume flushing in the next tick - Scheduler_scheduleCallback( - Scheduler_ImmediatePriority, - flushSyncCallbackQueue, - ); - throw error; - } finally { - isFlushingSyncQueue = false; } } }