Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature flag for setting update lane priority #19401

Merged
merged 5 commits into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions packages/react-dom/src/events/DeprecatedDOMEventResponderSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}
Expand Down
26 changes: 20 additions & 6 deletions packages/react-dom/src/events/ReactDOMEventListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {getClosestInstanceFromNode} from '../client/ReactDOMComponentTree';
import {
enableDeprecatedFlareAPI,
enableLegacyFBSupport,
enableSetUpdateLanePriority,
} from 'shared/ReactFeatureFlags';
import {
UserBlockingEvent,
Expand Down Expand Up @@ -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(
Expand All @@ -167,8 +183,6 @@ function dispatchUserBlockingUpdate(
nativeEvent,
),
);
} finally {
setCurrentUpdateLanePriority(previousPriority);
}
}

Expand Down
22 changes: 15 additions & 7 deletions packages/react-reconciler/src/ReactFiberHooks.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
enableDebugTracing,
enableSchedulingProfiler,
enableNewReconciler,
enableSetUpdateLanePriority,
} from 'shared/ReactFeatureFlags';

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

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,
() => {
setPending(true);
},
);

// 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,
Expand All @@ -1532,7 +1538,9 @@ function startTransition(setPending, config, callback) {
setPending(false);
callback();
} finally {
setCurrentUpdateLanePriority(previousLanePriority);
if (enableSetUpdateLanePriority && previousLanePriority != null) {
setCurrentUpdateLanePriority(previousLanePriority);
}
ReactCurrentBatchConfig.suspense = previousConfig;
}
},
Expand Down
22 changes: 15 additions & 7 deletions packages/react-reconciler/src/ReactFiberHooks.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
enableDebugTracing,
enableSchedulingProfiler,
enableNewReconciler,
enableSetUpdateLanePriority,
} from 'shared/ReactFeatureFlags';

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

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,
() => {
setPending(true);
},
);

// 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,
Expand All @@ -1532,7 +1538,9 @@ function startTransition(setPending, config, callback) {
setPending(false);
callback();
} finally {
setCurrentUpdateLanePriority(previousLanePriority);
if (enableSetUpdateLanePriority && previousLanePriority != null) {
setCurrentUpdateLanePriority(previousLanePriority);
}
ReactCurrentBatchConfig.suspense = previousConfig;
}
},
Expand Down
76 changes: 53 additions & 23 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
enableDebugTracing,
enableSchedulingProfiler,
enableScopeAPI,
enableSetUpdateLanePriority,
} from 'shared/ReactFeatureFlags';
import ReactSharedInternals from 'shared/ReactSharedInternals';
import invariant from 'shared/invariant';
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -1142,13 +1143,17 @@ export function flushDiscreteUpdates() {
}

export function deferredUpdates<A>(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);
}
}
}

Expand Down Expand Up @@ -1204,16 +1209,21 @@ export function discreteUpdates<A, B, C, D, R>(
): 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
Expand Down Expand Up @@ -1250,16 +1260,21 @@ export function flushSync<A, R>(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) {
rickhanlonii marked this conversation as resolved.
Show resolved Hide resolved
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
Expand All @@ -1271,12 +1286,17 @@ export function flushSync<A, R>(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();
rickhanlonii marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
}
Expand Down
Loading