Skip to content

Commit

Permalink
Move scheduler priority check into ReactDOM (#20778)
Browse files Browse the repository at this point in the history
* Move scheduler priority check into ReactDOM

* TODO
  • Loading branch information
gaearon committed Feb 9, 2021
1 parent ad8211d commit 3d10eca
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/react-dom/src/events/DOMEventNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export type DOMEventName =
| 'loadeddata'
| 'loadedmetadata'
| 'lostpointercapture'
| 'message'
| 'mousedown'
| 'mouseenter'
| 'mouseleave'
Expand Down
19 changes: 19 additions & 0 deletions packages/react-dom/src/events/ReactDOMEventListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,18 @@ 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,
} 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';

const InputDiscreteLanePriority = enableNewReconciler
? InputDiscreteLanePriority_new
Expand All @@ -79,6 +83,12 @@ const getCurrentUpdateLanePriority = enableNewReconciler
const setCurrentUpdateLanePriority = enableNewReconciler
? setCurrentUpdateLanePriority_new
: setCurrentUpdateLanePriority_old;
const schedulerPriorityToLanePriority = enableNewReconciler
? schedulerPriorityToLanePriority_new
: schedulerPriorityToLanePriority_old;
const getCurrentPriorityLevel = enableNewReconciler
? getCurrentPriorityLevel_new
: getCurrentPriorityLevel_old;

const {
unstable_UserBlockingPriority: UserBlockingPriority,
Expand Down Expand Up @@ -428,6 +438,15 @@ export function getEventPriority(domEventName: DOMEventName): * {
case 'mouseenter':
case 'mouseleave':
return InputContinuousLanePriority;
case 'message': {
// We might be in the Scheduler callback.
// 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:
return DefaultLanePriority;
}
Expand Down
10 changes: 1 addition & 9 deletions packages/react-reconciler/src/ReactFiberWorkLoop.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,15 +465,7 @@ export function requestUpdateLane(fiber: Fiber): Lane {
} else {
if (enableNativeEventPriorityInference) {
const eventLanePriority = getCurrentEventPriority();
if (eventLanePriority === DefaultLanePriority) {
// TODO: move this case into the ReactDOM host config.
const schedulerLanePriority = schedulerPriorityToLanePriority(
schedulerPriority,
);
lane = findUpdateLane(schedulerLanePriority, currentEventWipLanes);
} else {
lane = findUpdateLane(eventLanePriority, currentEventWipLanes);
}
lane = findUpdateLane(eventLanePriority, currentEventWipLanes);
} else {
const schedulerLanePriority = schedulerPriorityToLanePriority(
schedulerPriority,
Expand Down

0 comments on commit 3d10eca

Please sign in to comment.