Skip to content

Attach updatePriority to root #25466

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactEventPriorities.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
isHigherEventPriority as isHigherEventPriority_new,
} from './ReactEventPriorities.new';

export opaque type EventPriority = number;
export type EventPriority = number;

export const DiscreteEventPriority: EventPriority = enableNewReconciler
? (DiscreteEventPriority_new: any)
Expand Down
21 changes: 17 additions & 4 deletions packages/react-reconciler/src/ReactEventPriorities.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ import {
includesNonIdleWork,
} from './ReactFiberLane.new';

export opaque type EventPriority = Lane;
// TODO: Ideally this would be opaque but that doesn't work well with
// our reconciler fork infra, since these leak into non-reconciler packages.
export type EventPriority = number;

export const NoEventPriority: EventPriority = NoLane;
export const DiscreteEventPriority: EventPriority = SyncLane;
export const ContinuousEventPriority: EventPriority = InputContinuousLane;
export const DefaultEventPriority: EventPriority = DefaultLane;
export const ContinuousEventPriority: EventPriority = SyncLane | (2 << 1);
export const DefaultEventPriority: EventPriority = SyncLane | (1 << 1);
export const IdleEventPriority: EventPriority = IdleLane;

let currentUpdatePriority: EventPriority = NoLane;
let currentUpdatePriority: EventPriority = NoEventPriority;

export function getCurrentUpdatePriority(): EventPriority {
return currentUpdatePriority;
Expand Down Expand Up @@ -80,3 +83,13 @@ export function lanesToEventPriority(lanes: Lanes): EventPriority {
}
return IdleEventPriority;
}

export function laneToEventPriority(lane: Lane): EventPriority {
if (lane === DefaultLane) {
return DefaultEventPriority;
}
if (lane === InputContinuousLane) {
return ContinuousEventPriority;
}
return (lane: any);
}
21 changes: 17 additions & 4 deletions packages/react-reconciler/src/ReactEventPriorities.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ import {
includesNonIdleWork,
} from './ReactFiberLane.old';

export opaque type EventPriority = Lane;
// TODO: Ideally this would be opaque but that doesn't work well with
// our reconciler fork infra, since these leak into non-reconciler packages.
export type EventPriority = number;

export const NoEventPriority: EventPriority = NoLane;
export const DiscreteEventPriority: EventPriority = SyncLane;
export const ContinuousEventPriority: EventPriority = InputContinuousLane;
export const DefaultEventPriority: EventPriority = DefaultLane;
export const ContinuousEventPriority: EventPriority = SyncLane | (2 << 1);
export const DefaultEventPriority: EventPriority = SyncLane | (1 << 1);
export const IdleEventPriority: EventPriority = IdleLane;

let currentUpdatePriority: EventPriority = NoLane;
let currentUpdatePriority: EventPriority = NoEventPriority;

export function getCurrentUpdatePriority(): EventPriority {
return currentUpdatePriority;
Expand Down Expand Up @@ -80,3 +83,13 @@ export function lanesToEventPriority(lanes: Lanes): EventPriority {
}
return IdleEventPriority;
}

export function laneToEventPriority(lane: Lane): EventPriority {
if (lane === DefaultLane) {
return DefaultEventPriority;
}
if (lane === InputContinuousLane) {
return ContinuousEventPriority;
}
return (lane: any);
}
2 changes: 2 additions & 0 deletions packages/react-reconciler/src/ReactFiberBeginWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ import {
pushRootMarkerInstance,
TransitionTracingMarker,
} from './ReactFiberTracingMarkerComponent.new';
import {NoEventPriority} from './ReactEventPriorities.new';

const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;

Expand Down Expand Up @@ -2821,6 +2822,7 @@ function updateDehydratedSuspenseComponent(
current,
attemptHydrationAtLane,
eventTime,
NoEventPriority,
);
} else {
// We have already tried to ping at a higher priority than we're rendering with
Expand Down
2 changes: 2 additions & 0 deletions packages/react-reconciler/src/ReactFiberBeginWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ import {
pushRootMarkerInstance,
TransitionTracingMarker,
} from './ReactFiberTracingMarkerComponent.old';
import {NoEventPriority} from './ReactEventPriorities.old';

const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;

Expand Down Expand Up @@ -2821,6 +2822,7 @@ function updateDehydratedSuspenseComponent(
current,
attemptHydrationAtLane,
eventTime,
NoEventPriority,
);
} else {
// We have already tried to ping at a higher priority than we're rendering with
Expand Down
10 changes: 7 additions & 3 deletions packages/react-reconciler/src/ReactFiberClassComponent.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import {readContext, checkIfContextChanged} from './ReactFiberNewContext.new';
import {
requestEventTime,
requestUpdateLane,
requestUpdateLane_getUpdatePriority,
scheduleUpdateOnFiber,
} from './ReactFiberWorkLoop.new';
import {logForceUpdateScheduled, logStateUpdateScheduled} from './DebugTracing';
Expand Down Expand Up @@ -204,6 +205,7 @@ const classComponentUpdater = {
const fiber = getInstance(inst);
const eventTime = requestEventTime();
const lane = requestUpdateLane(fiber);
const updatePriority = requestUpdateLane_getUpdatePriority();

const update = createUpdate(eventTime, lane);
update.payload = payload;
Expand All @@ -216,7 +218,7 @@ const classComponentUpdater = {

const root = enqueueUpdate(fiber, update, lane);
if (root !== null) {
scheduleUpdateOnFiber(root, fiber, lane, eventTime);
scheduleUpdateOnFiber(root, fiber, lane, eventTime, updatePriority);
entangleTransitions(root, fiber, lane);
}

Expand All @@ -237,6 +239,7 @@ const classComponentUpdater = {
const fiber = getInstance(inst);
const eventTime = requestEventTime();
const lane = requestUpdateLane(fiber);
const updatePriority = requestUpdateLane_getUpdatePriority();

const update = createUpdate(eventTime, lane);
update.tag = ReplaceState;
Expand All @@ -251,7 +254,7 @@ const classComponentUpdater = {

const root = enqueueUpdate(fiber, update, lane);
if (root !== null) {
scheduleUpdateOnFiber(root, fiber, lane, eventTime);
scheduleUpdateOnFiber(root, fiber, lane, eventTime, updatePriority);
entangleTransitions(root, fiber, lane);
}

Expand All @@ -272,6 +275,7 @@ const classComponentUpdater = {
const fiber = getInstance(inst);
const eventTime = requestEventTime();
const lane = requestUpdateLane(fiber);
const updatePriority = requestUpdateLane_getUpdatePriority();

const update = createUpdate(eventTime, lane);
update.tag = ForceUpdate;
Expand All @@ -285,7 +289,7 @@ const classComponentUpdater = {

const root = enqueueUpdate(fiber, update, lane);
if (root !== null) {
scheduleUpdateOnFiber(root, fiber, lane, eventTime);
scheduleUpdateOnFiber(root, fiber, lane, eventTime, updatePriority);
entangleTransitions(root, fiber, lane);
}

Expand Down
10 changes: 7 additions & 3 deletions packages/react-reconciler/src/ReactFiberClassComponent.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import {readContext, checkIfContextChanged} from './ReactFiberNewContext.old';
import {
requestEventTime,
requestUpdateLane,
requestUpdateLane_getUpdatePriority,
scheduleUpdateOnFiber,
} from './ReactFiberWorkLoop.old';
import {logForceUpdateScheduled, logStateUpdateScheduled} from './DebugTracing';
Expand Down Expand Up @@ -204,6 +205,7 @@ const classComponentUpdater = {
const fiber = getInstance(inst);
const eventTime = requestEventTime();
const lane = requestUpdateLane(fiber);
const updatePriority = requestUpdateLane_getUpdatePriority();

const update = createUpdate(eventTime, lane);
update.payload = payload;
Expand All @@ -216,7 +218,7 @@ const classComponentUpdater = {

const root = enqueueUpdate(fiber, update, lane);
if (root !== null) {
scheduleUpdateOnFiber(root, fiber, lane, eventTime);
scheduleUpdateOnFiber(root, fiber, lane, eventTime, updatePriority);
entangleTransitions(root, fiber, lane);
}

Expand All @@ -237,6 +239,7 @@ const classComponentUpdater = {
const fiber = getInstance(inst);
const eventTime = requestEventTime();
const lane = requestUpdateLane(fiber);
const updatePriority = requestUpdateLane_getUpdatePriority();

const update = createUpdate(eventTime, lane);
update.tag = ReplaceState;
Expand All @@ -251,7 +254,7 @@ const classComponentUpdater = {

const root = enqueueUpdate(fiber, update, lane);
if (root !== null) {
scheduleUpdateOnFiber(root, fiber, lane, eventTime);
scheduleUpdateOnFiber(root, fiber, lane, eventTime, updatePriority);
entangleTransitions(root, fiber, lane);
}

Expand All @@ -272,6 +275,7 @@ const classComponentUpdater = {
const fiber = getInstance(inst);
const eventTime = requestEventTime();
const lane = requestUpdateLane(fiber);
const updatePriority = requestUpdateLane_getUpdatePriority();

const update = createUpdate(eventTime, lane);
update.tag = ForceUpdate;
Expand All @@ -285,7 +289,7 @@ const classComponentUpdater = {

const root = enqueueUpdate(fiber, update, lane);
if (root !== null) {
scheduleUpdateOnFiber(root, fiber, lane, eventTime);
scheduleUpdateOnFiber(root, fiber, lane, eventTime, updatePriority);
entangleTransitions(root, fiber, lane);
}

Expand Down
25 changes: 21 additions & 4 deletions packages/react-reconciler/src/ReactFiberHooks.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import {
getCurrentUpdatePriority,
setCurrentUpdatePriority,
higherEventPriority,
DiscreteEventPriority,
} from './ReactEventPriorities.new';
import {readContext, checkIfContextChanged} from './ReactFiberNewContext.new';
import {HostRoot, CacheComponent} from './ReactWorkTags';
Expand Down Expand Up @@ -104,6 +105,7 @@ import {
requestEventTime,
markSkippedUpdateLanes,
isInvalidExecutionContextForEventFunction,
requestUpdateLane_getUpdatePriority,
} from './ReactFiberWorkLoop.new';

import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber';
Expand Down Expand Up @@ -1670,7 +1672,13 @@ function checkIfSnapshotChanged<T>(inst: StoreInstance<T>): boolean {
function forceStoreRerender(fiber) {
const root = enqueueConcurrentRenderForLane(fiber, SyncLane);
if (root !== null) {
scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp);
scheduleUpdateOnFiber(
root,
fiber,
SyncLane,
NoTimestamp,
DiscreteEventPriority,
);
}
}

Expand Down Expand Up @@ -2381,11 +2389,18 @@ function refreshCache<T>(fiber: Fiber, seedKey: ?() => T, seedValue: T) {
case HostRoot: {
// Schedule an update on the cache boundary to trigger a refresh.
const lane = requestUpdateLane(provider);
const updatePriority = requestUpdateLane_getUpdatePriority();
const eventTime = requestEventTime();
const refreshUpdate = createLegacyQueueUpdate(eventTime, lane);
const root = enqueueLegacyQueueUpdate(provider, refreshUpdate, lane);
if (root !== null) {
scheduleUpdateOnFiber(root, provider, lane, eventTime);
scheduleUpdateOnFiber(
root,
provider,
lane,
eventTime,
updatePriority,
);
entangleLegacyQueueTransitions(root, provider, lane);
}

Expand Down Expand Up @@ -2427,6 +2442,7 @@ function dispatchReducerAction<S, A>(
}

const lane = requestUpdateLane(fiber);
const updatePriority = requestUpdateLane_getUpdatePriority();

const update: Update<S, A> = {
lane,
Expand All @@ -2442,7 +2458,7 @@ function dispatchReducerAction<S, A>(
const root = enqueueConcurrentHookUpdate(fiber, queue, update, lane);
if (root !== null) {
const eventTime = requestEventTime();
scheduleUpdateOnFiber(root, fiber, lane, eventTime);
scheduleUpdateOnFiber(root, fiber, lane, eventTime, updatePriority);
entangleTransitionUpdate(root, queue, lane);
}
}
Expand All @@ -2466,6 +2482,7 @@ function dispatchSetState<S, A>(
}

const lane = requestUpdateLane(fiber);
const updatePriority = requestUpdateLane_getUpdatePriority();

const update: Update<S, A> = {
lane,
Expand Down Expand Up @@ -2524,7 +2541,7 @@ function dispatchSetState<S, A>(
const root = enqueueConcurrentHookUpdate(fiber, queue, update, lane);
if (root !== null) {
const eventTime = requestEventTime();
scheduleUpdateOnFiber(root, fiber, lane, eventTime);
scheduleUpdateOnFiber(root, fiber, lane, eventTime, updatePriority);
entangleTransitionUpdate(root, queue, lane);
}
}
Expand Down
Loading