Skip to content

Commit

Permalink
Wire up event priority to the work loop
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Feb 5, 2021
1 parent 6bfc2fb commit 6f5c118
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 10 deletions.
41 changes: 36 additions & 5 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ import {
disableSchedulerTimeoutInWorkLoop,
enableDoubleInvokingEffects,
skipUnmountedBoundaries,
enableNativeEventPriorityInference,
} from 'shared/ReactFeatureFlags';
import ReactSharedInternals from 'shared/ReactSharedInternals';
import {DefaultEvent, DiscreteEvent, ContinuousEvent} from 'shared/ReactTypes';
import invariant from 'shared/invariant';

import {
Expand Down Expand Up @@ -93,6 +95,7 @@ import {
afterActiveInstanceBlur,
clearContainer,
scheduleMicrotask,
getCurrentEventPriority,
} from './ReactFiberHostConfig';

import {
Expand Down Expand Up @@ -138,6 +141,7 @@ import {
SyncLanePriority,
SyncBatchedLanePriority,
InputDiscreteLanePriority,
InputContinuousLanePriority,
DefaultLanePriority,
NoLanes,
NoLane,
Expand Down Expand Up @@ -465,11 +469,38 @@ export function requestUpdateLane(fiber: Fiber): Lane {
const currentLanePriority = getCurrentUpdateLanePriority();
lane = findUpdateLane(currentLanePriority, currentEventWipLanes);
} else {
const schedulerLanePriority = schedulerPriorityToLanePriority(
schedulerPriority,
);

lane = findUpdateLane(schedulerLanePriority, currentEventWipLanes);
let eventPriority = DefaultEvent;
if (enableNativeEventPriorityInference) {
eventPriority = getCurrentEventPriority();
}
switch (eventPriority) {
case DiscreteEvent: {
lane = findUpdateLane(InputDiscreteLanePriority, currentEventWipLanes);
break;
}
case ContinuousEvent: {
lane = findUpdateLane(
InputContinuousLanePriority,
currentEventWipLanes,
);
break;
}
default: {
if (__DEV__) {
console.error(
'Invalid event priority returned from getCurrentEventPriority: %s.',
eventPriority,
);
}
}
// eslint-disable-next-line no-fallthrough
case DefaultEvent: {
const schedulerLanePriority = schedulerPriorityToLanePriority(
schedulerPriority,
);
lane = findUpdateLane(schedulerLanePriority, currentEventWipLanes);
}
}
}

return lane;
Expand Down
41 changes: 36 additions & 5 deletions packages/react-reconciler/src/ReactFiberWorkLoop.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ import {
disableSchedulerTimeoutInWorkLoop,
enableDoubleInvokingEffects,
skipUnmountedBoundaries,
enableNativeEventPriorityInference,
} from 'shared/ReactFeatureFlags';
import ReactSharedInternals from 'shared/ReactSharedInternals';
import {DefaultEvent, DiscreteEvent, ContinuousEvent} from 'shared/ReactTypes';
import invariant from 'shared/invariant';

import {
Expand Down Expand Up @@ -93,6 +95,7 @@ import {
afterActiveInstanceBlur,
clearContainer,
scheduleMicrotask,
getCurrentEventPriority,
} from './ReactFiberHostConfig';

import {
Expand Down Expand Up @@ -138,6 +141,7 @@ import {
SyncLanePriority,
SyncBatchedLanePriority,
InputDiscreteLanePriority,
InputContinuousLanePriority,
DefaultLanePriority,
NoLanes,
NoLane,
Expand Down Expand Up @@ -465,11 +469,38 @@ export function requestUpdateLane(fiber: Fiber): Lane {
const currentLanePriority = getCurrentUpdateLanePriority();
lane = findUpdateLane(currentLanePriority, currentEventWipLanes);
} else {
const schedulerLanePriority = schedulerPriorityToLanePriority(
schedulerPriority,
);

lane = findUpdateLane(schedulerLanePriority, currentEventWipLanes);
let eventPriority = DefaultEvent;
if (enableNativeEventPriorityInference) {
eventPriority = getCurrentEventPriority();
}
switch (eventPriority) {
case DiscreteEvent: {
lane = findUpdateLane(InputDiscreteLanePriority, currentEventWipLanes);
break;
}
case ContinuousEvent: {
lane = findUpdateLane(
InputContinuousLanePriority,
currentEventWipLanes,
);
break;
}
default: {
if (__DEV__) {
console.error(
'Invalid event priority returned from getCurrentEventPriority: %s.',
eventPriority,
);
}
}
// eslint-disable-next-line no-fallthrough
case DefaultEvent: {
const schedulerLanePriority = schedulerPriorityToLanePriority(
schedulerPriority,
);
lane = findUpdateLane(schedulerLanePriority, currentEventWipLanes);
}
}
}

return lane;
Expand Down

0 comments on commit 6f5c118

Please sign in to comment.