Skip to content

Commit

Permalink
Land enableNativeEventPriorityInference (#20955)
Browse files Browse the repository at this point in the history
* Land enableNativeEventPriorityInference

* Move schedulerPriorityToLanePriority

* Remove obsolete comment
  • Loading branch information
rickhanlonii authored Mar 10, 2021
1 parent 5d1d167 commit e4d4b70
Show file tree
Hide file tree
Showing 19 changed files with 45 additions and 208 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
}

// @gate experimental
// @gate enableNativeEventPriorityInference
it('ignores discrete events on a pending removed element', async () => {
const disableButtonRef = React.createRef();
const submitButtonRef = React.createRef();
Expand Down Expand Up @@ -95,7 +94,6 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
});

// @gate experimental
// @gate enableNativeEventPriorityInference
it('ignores discrete events on a pending removed event listener', async () => {
const disableButtonRef = React.createRef();
const submitButtonRef = React.createRef();
Expand Down Expand Up @@ -165,7 +163,6 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
});

// @gate experimental
// @gate enableNativeEventPriorityInference
it('uses the newest discrete events on a pending changed event listener', async () => {
const enableButtonRef = React.createRef();
const submitButtonRef = React.createRef();
Expand Down Expand Up @@ -229,7 +226,6 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
});

// @gate experimental
// @gate enableNativeEventPriorityInference
it('mouse over should be user-blocking but not discrete', async () => {
const root = ReactDOM.unstable_createRoot(container);

Expand Down Expand Up @@ -260,7 +256,6 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
});

// @gate experimental
// @gate enableNativeEventPriorityInference
it('mouse enter should be user-blocking but not discrete', async () => {
const root = ReactDOM.unstable_createRoot(container);

Expand Down
44 changes: 35 additions & 9 deletions packages/react-dom/src/events/ReactDOMEventListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
*/

import type {AnyNativeEvent} from '../events/PluginModuleType';
import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
import type {
FiberRoot,
ReactPriorityLevel,
} from 'react-reconciler/src/ReactInternalTypes';
import type {Container, SuspenseInstance} from '../client/ReactDOMHostConfig';
import type {DOMEventName} from '../events/DOMEventNames';

Expand Down Expand Up @@ -50,18 +53,27 @@ import {
DefaultLanePriority as DefaultLanePriority_old,
getCurrentUpdateLanePriority as getCurrentUpdateLanePriority_old,
setCurrentUpdateLanePriority as setCurrentUpdateLanePriority_old,
schedulerPriorityToLanePriority as schedulerPriorityToLanePriority_old,
} from 'react-reconciler/src/ReactFiberLane.old';
import {
InputDiscreteLanePriority as InputDiscreteLanePriority_new,
InputContinuousLanePriority as InputContinuousLanePriority_new,
DefaultLanePriority as DefaultLanePriority_new,
getCurrentUpdateLanePriority as getCurrentUpdateLanePriority_new,
setCurrentUpdateLanePriority as setCurrentUpdateLanePriority_new,
schedulerPriorityToLanePriority as schedulerPriorityToLanePriority_new,
SyncLanePriority,
IdleLanePriority,
NoLanePriority,
} from 'react-reconciler/src/ReactFiberLane.new';
import {getCurrentPriorityLevel as getCurrentPriorityLevel_old} from 'react-reconciler/src/SchedulerWithReactIntegration.old';
import {getCurrentPriorityLevel as getCurrentPriorityLevel_new} from 'react-reconciler/src/SchedulerWithReactIntegration.new';
import {
getCurrentPriorityLevel as getCurrentPriorityLevel_new,
IdlePriority as IdleSchedulerPriority,
ImmediatePriority as ImmediateSchedulerPriority,
LowPriority as LowSchedulerPriority,
NormalPriority as NormalSchedulerPriority,
UserBlockingPriority as UserBlockingSchedulerPriority,
} from 'react-reconciler/src/SchedulerWithReactIntegration.new';
import type {LanePriority} from 'react-reconciler/src/ReactFiberLane.new';

const InputDiscreteLanePriority = enableNewReconciler
? InputDiscreteLanePriority_new
Expand All @@ -78,13 +90,29 @@ const getCurrentUpdateLanePriority = enableNewReconciler
const setCurrentUpdateLanePriority = enableNewReconciler
? setCurrentUpdateLanePriority_new
: setCurrentUpdateLanePriority_old;
const schedulerPriorityToLanePriority = enableNewReconciler
? schedulerPriorityToLanePriority_new
: schedulerPriorityToLanePriority_old;
const getCurrentPriorityLevel = enableNewReconciler
? getCurrentPriorityLevel_new
: getCurrentPriorityLevel_old;

function schedulerPriorityToLanePriority(
schedulerPriorityLevel: ReactPriorityLevel,
): LanePriority {
switch (schedulerPriorityLevel) {
case ImmediateSchedulerPriority:
return SyncLanePriority;
case UserBlockingSchedulerPriority:
return InputContinuousLanePriority;
case NormalSchedulerPriority:
case LowSchedulerPriority:
// TODO: Handle LowSchedulerPriority, somehow. Maybe the same lane as hydration.
return DefaultLanePriority;
case IdleSchedulerPriority:
return IdleLanePriority;
default:
return NoLanePriority;
}
}

// TODO: can we stop exporting these?
export let _enabled = true;

Expand Down Expand Up @@ -410,8 +438,6 @@ export function getEventPriority(domEventName: DOMEventName): * {
// Eventually this mechanism will be replaced by a check
// of the current priority on the native scheduler.
const schedulerPriority = getCurrentPriorityLevel();
// TODO: Inline schedulerPriorityToLanePriority into this file
// when we delete the enableNativeEventPriorityInference flag.
return schedulerPriorityToLanePriority(schedulerPriority);
}
default:
Expand Down
20 changes: 6 additions & 14 deletions packages/react-noop-renderer/src/createReactNoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
LegacyRoot,
} from 'react-reconciler/src/ReactRootTags';

import {enableNativeEventPriorityInference} from 'shared/ReactFeatureFlags';
import ReactSharedInternals from 'shared/ReactSharedInternals';
import enqueueTask from 'shared/enqueueTask';
const {IsSomeRendererActing} = ReactSharedInternals;
Expand Down Expand Up @@ -934,19 +933,12 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
discreteUpdates: NoopRenderer.discreteUpdates,

idleUpdates<T>(fn: () => T): T {
if (enableNativeEventPriorityInference) {
const prevEventPriority = currentEventPriority;
currentEventPriority = NoopRenderer.IdleEventPriority;
try {
fn();
} finally {
currentEventPriority = prevEventPriority;
}
} else {
return Scheduler.unstable_runWithPriority(
Scheduler.unstable_IdlePriority,
fn,
);
const prevEventPriority = currentEventPriority;
currentEventPriority = NoopRenderer.IdleEventPriority;
try {
fn();
} finally {
currentEventPriority = prevEventPriority;
}
},

Expand Down
20 changes: 0 additions & 20 deletions packages/react-reconciler/src/ReactFiberLane.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import {
ImmediatePriority as ImmediateSchedulerPriority,
UserBlockingPriority as UserBlockingSchedulerPriority,
NormalPriority as NormalSchedulerPriority,
LowPriority as LowSchedulerPriority,
IdlePriority as IdleSchedulerPriority,
NoPriority as NoSchedulerPriority,
} from './SchedulerWithReactIntegration.new';
Expand Down Expand Up @@ -275,25 +274,6 @@ function getHighestPriorityLanes(lanes: Lanes | Lane): Lanes {
}
}

export function schedulerPriorityToLanePriority(
schedulerPriorityLevel: ReactPriorityLevel,
): LanePriority {
switch (schedulerPriorityLevel) {
case ImmediateSchedulerPriority:
return SyncLanePriority;
case UserBlockingSchedulerPriority:
return InputContinuousLanePriority;
case NormalSchedulerPriority:
case LowSchedulerPriority:
// TODO: Handle LowSchedulerPriority, somehow. Maybe the same lane as hydration.
return DefaultLanePriority;
case IdleSchedulerPriority:
return IdleLanePriority;
default:
return NoLanePriority;
}
}

export function lanePriorityToSchedulerPriority(
lanePriority: LanePriority,
): ReactPriorityLevel {
Expand Down
20 changes: 0 additions & 20 deletions packages/react-reconciler/src/ReactFiberLane.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import {
ImmediatePriority as ImmediateSchedulerPriority,
UserBlockingPriority as UserBlockingSchedulerPriority,
NormalPriority as NormalSchedulerPriority,
LowPriority as LowSchedulerPriority,
IdlePriority as IdleSchedulerPriority,
NoPriority as NoSchedulerPriority,
} from './SchedulerWithReactIntegration.old';
Expand Down Expand Up @@ -275,25 +274,6 @@ function getHighestPriorityLanes(lanes: Lanes | Lane): Lanes {
}
}

export function schedulerPriorityToLanePriority(
schedulerPriorityLevel: ReactPriorityLevel,
): LanePriority {
switch (schedulerPriorityLevel) {
case ImmediateSchedulerPriority:
return SyncLanePriority;
case UserBlockingSchedulerPriority:
return InputContinuousLanePriority;
case NormalSchedulerPriority:
case LowSchedulerPriority:
// TODO: Handle LowSchedulerPriority, somehow. Maybe the same lane as hydration.
return DefaultLanePriority;
case IdleSchedulerPriority:
return IdleLanePriority;
default:
return NoLanePriority;
}
}

export function lanePriorityToSchedulerPriority(
lanePriority: LanePriority,
): ReactPriorityLevel {
Expand Down
13 changes: 2 additions & 11 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import {
disableSchedulerTimeoutInWorkLoop,
enableStrictEffects,
skipUnmountedBoundaries,
enableNativeEventPriorityInference,
} from 'shared/ReactFeatureFlags';
import ReactSharedInternals from 'shared/ReactSharedInternals';
import invariant from 'shared/invariant';
Expand Down Expand Up @@ -168,7 +167,6 @@ import {
markRootExpired,
markDiscreteUpdatesExpired,
markRootFinished,
schedulerPriorityToLanePriority,
lanePriorityToSchedulerPriority,
higherLanePriority,
} from './ReactFiberLane.new';
Expand Down Expand Up @@ -456,15 +454,8 @@ export function requestUpdateLane(fiber: Fiber): Lane {
const currentLanePriority = getCurrentUpdateLanePriority();
lane = findUpdateLane(currentLanePriority);
} else {
if (enableNativeEventPriorityInference) {
const eventLanePriority = getCurrentEventPriority();
lane = findUpdateLane(eventLanePriority);
} else {
const schedulerLanePriority = schedulerPriorityToLanePriority(
schedulerPriority,
);
lane = findUpdateLane(schedulerLanePriority);
}
const eventLanePriority = getCurrentEventPriority();
lane = findUpdateLane(eventLanePriority);
}

return lane;
Expand Down
13 changes: 2 additions & 11 deletions packages/react-reconciler/src/ReactFiberWorkLoop.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import {
disableSchedulerTimeoutInWorkLoop,
enableStrictEffects,
skipUnmountedBoundaries,
enableNativeEventPriorityInference,
} from 'shared/ReactFeatureFlags';
import ReactSharedInternals from 'shared/ReactSharedInternals';
import invariant from 'shared/invariant';
Expand Down Expand Up @@ -168,7 +167,6 @@ import {
markRootExpired,
markDiscreteUpdatesExpired,
markRootFinished,
schedulerPriorityToLanePriority,
lanePriorityToSchedulerPriority,
higherLanePriority,
} from './ReactFiberLane.old';
Expand Down Expand Up @@ -456,15 +454,8 @@ export function requestUpdateLane(fiber: Fiber): Lane {
const currentLanePriority = getCurrentUpdateLanePriority();
lane = findUpdateLane(currentLanePriority);
} else {
if (enableNativeEventPriorityInference) {
const eventLanePriority = getCurrentEventPriority();
lane = findUpdateLane(eventLanePriority);
} else {
const schedulerLanePriority = schedulerPriorityToLanePriority(
schedulerPriority,
);
lane = findUpdateLane(schedulerLanePriority);
}
const eventLanePriority = getCurrentEventPriority();
lane = findUpdateLane(eventLanePriority);
}

return lane;
Expand Down
Loading

0 comments on commit e4d4b70

Please sign in to comment.