From 651346967bcfa819e45b31ea35d562699f50feaa Mon Sep 17 00:00:00 2001 From: Tianyu Yao Date: Mon, 10 Oct 2022 21:55:32 -0700 Subject: [PATCH] Attach updatePriority to root --- .../src/ReactFiberBeginWork.new.js | 2 + .../src/ReactFiberBeginWork.old.js | 2 + .../src/ReactFiberClassComponent.new.js | 10 ++- .../src/ReactFiberClassComponent.old.js | 10 ++- .../src/ReactFiberHooks.new.js | 25 +++++- .../src/ReactFiberHooks.old.js | 25 +++++- .../src/ReactFiberHotReloading.new.js | 9 +- .../src/ReactFiberHotReloading.old.js | 9 +- .../src/ReactFiberLane.new.js | 3 + .../src/ReactFiberLane.old.js | 3 + .../src/ReactFiberReconciler.new.js | 85 ++++++++++++++++--- .../src/ReactFiberReconciler.old.js | 85 ++++++++++++++++--- .../src/ReactFiberRoot.new.js | 1 + .../src/ReactFiberRoot.old.js | 1 + .../src/ReactFiberWorkLoop.new.js | 22 +++-- .../src/ReactFiberWorkLoop.old.js | 22 +++-- .../src/ReactInternalTypes.js | 1 + 17 files changed, 265 insertions(+), 50 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberBeginWork.new.js b/packages/react-reconciler/src/ReactFiberBeginWork.new.js index 9e9c4bd970..92b90ede2d 100644 --- a/packages/react-reconciler/src/ReactFiberBeginWork.new.js +++ b/packages/react-reconciler/src/ReactFiberBeginWork.new.js @@ -275,6 +275,7 @@ import { pushRootMarkerInstance, TransitionTracingMarker, } from './ReactFiberTracingMarkerComponent.new'; +import {NoEventPriority} from './ReactEventPriorities.new'; const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner; @@ -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 diff --git a/packages/react-reconciler/src/ReactFiberBeginWork.old.js b/packages/react-reconciler/src/ReactFiberBeginWork.old.js index bd12a98980..2b3aad9985 100644 --- a/packages/react-reconciler/src/ReactFiberBeginWork.old.js +++ b/packages/react-reconciler/src/ReactFiberBeginWork.old.js @@ -275,6 +275,7 @@ import { pushRootMarkerInstance, TransitionTracingMarker, } from './ReactFiberTracingMarkerComponent.old'; +import {NoEventPriority} from './ReactEventPriorities.old'; const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner; @@ -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 diff --git a/packages/react-reconciler/src/ReactFiberClassComponent.new.js b/packages/react-reconciler/src/ReactFiberClassComponent.new.js index de7e7bbba7..ae0a888bb1 100644 --- a/packages/react-reconciler/src/ReactFiberClassComponent.new.js +++ b/packages/react-reconciler/src/ReactFiberClassComponent.new.js @@ -70,6 +70,7 @@ import {readContext, checkIfContextChanged} from './ReactFiberNewContext.new'; import { requestEventTime, requestUpdateLane, + requestUpdateLane_getUpdatePriority, scheduleUpdateOnFiber, } from './ReactFiberWorkLoop.new'; import {logForceUpdateScheduled, logStateUpdateScheduled} from './DebugTracing'; @@ -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; @@ -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); } @@ -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; @@ -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); } @@ -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; @@ -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); } diff --git a/packages/react-reconciler/src/ReactFiberClassComponent.old.js b/packages/react-reconciler/src/ReactFiberClassComponent.old.js index 5625c682c6..1b5e195ad6 100644 --- a/packages/react-reconciler/src/ReactFiberClassComponent.old.js +++ b/packages/react-reconciler/src/ReactFiberClassComponent.old.js @@ -70,6 +70,7 @@ import {readContext, checkIfContextChanged} from './ReactFiberNewContext.old'; import { requestEventTime, requestUpdateLane, + requestUpdateLane_getUpdatePriority, scheduleUpdateOnFiber, } from './ReactFiberWorkLoop.old'; import {logForceUpdateScheduled, logStateUpdateScheduled} from './DebugTracing'; @@ -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; @@ -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); } @@ -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; @@ -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); } @@ -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; @@ -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); } diff --git a/packages/react-reconciler/src/ReactFiberHooks.new.js b/packages/react-reconciler/src/ReactFiberHooks.new.js index f430a4cad6..892ad660ef 100644 --- a/packages/react-reconciler/src/ReactFiberHooks.new.js +++ b/packages/react-reconciler/src/ReactFiberHooks.new.js @@ -77,6 +77,7 @@ import { getCurrentUpdatePriority, setCurrentUpdatePriority, higherEventPriority, + DiscreteEventPriority, } from './ReactEventPriorities.new'; import {readContext, checkIfContextChanged} from './ReactFiberNewContext.new'; import {HostRoot, CacheComponent} from './ReactWorkTags'; @@ -104,6 +105,7 @@ import { requestEventTime, markSkippedUpdateLanes, isInvalidExecutionContextForEventFunction, + requestUpdateLane_getUpdatePriority, } from './ReactFiberWorkLoop.new'; import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber'; @@ -1670,7 +1672,13 @@ function checkIfSnapshotChanged(inst: StoreInstance): boolean { function forceStoreRerender(fiber) { const root = enqueueConcurrentRenderForLane(fiber, SyncLane); if (root !== null) { - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp); + scheduleUpdateOnFiber( + root, + fiber, + SyncLane, + NoTimestamp, + DiscreteEventPriority, + ); } } @@ -2381,11 +2389,18 @@ function refreshCache(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); } @@ -2427,6 +2442,7 @@ function dispatchReducerAction( } const lane = requestUpdateLane(fiber); + const updatePriority = requestUpdateLane_getUpdatePriority(); const update: Update = { lane, @@ -2442,7 +2458,7 @@ function dispatchReducerAction( 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); } } @@ -2466,6 +2482,7 @@ function dispatchSetState( } const lane = requestUpdateLane(fiber); + const updatePriority = requestUpdateLane_getUpdatePriority(); const update: Update = { lane, @@ -2524,7 +2541,7 @@ function dispatchSetState( 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); } } diff --git a/packages/react-reconciler/src/ReactFiberHooks.old.js b/packages/react-reconciler/src/ReactFiberHooks.old.js index d5add2ffec..23dde206b5 100644 --- a/packages/react-reconciler/src/ReactFiberHooks.old.js +++ b/packages/react-reconciler/src/ReactFiberHooks.old.js @@ -77,6 +77,7 @@ import { getCurrentUpdatePriority, setCurrentUpdatePriority, higherEventPriority, + DiscreteEventPriority, } from './ReactEventPriorities.old'; import {readContext, checkIfContextChanged} from './ReactFiberNewContext.old'; import {HostRoot, CacheComponent} from './ReactWorkTags'; @@ -104,6 +105,7 @@ import { requestEventTime, markSkippedUpdateLanes, isInvalidExecutionContextForEventFunction, + requestUpdateLane_getUpdatePriority, } from './ReactFiberWorkLoop.old'; import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber'; @@ -1670,7 +1672,13 @@ function checkIfSnapshotChanged(inst: StoreInstance): boolean { function forceStoreRerender(fiber) { const root = enqueueConcurrentRenderForLane(fiber, SyncLane); if (root !== null) { - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp); + scheduleUpdateOnFiber( + root, + fiber, + SyncLane, + NoTimestamp, + DiscreteEventPriority, + ); } } @@ -2381,11 +2389,18 @@ function refreshCache(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); } @@ -2427,6 +2442,7 @@ function dispatchReducerAction( } const lane = requestUpdateLane(fiber); + const updatePriority = requestUpdateLane_getUpdatePriority(); const update: Update = { lane, @@ -2442,7 +2458,7 @@ function dispatchReducerAction( 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); } } @@ -2466,6 +2482,7 @@ function dispatchSetState( } const lane = requestUpdateLane(fiber); + const updatePriority = requestUpdateLane_getUpdatePriority(); const update: Update = { lane, @@ -2524,7 +2541,7 @@ function dispatchSetState( 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); } } diff --git a/packages/react-reconciler/src/ReactFiberHotReloading.new.js b/packages/react-reconciler/src/ReactFiberHotReloading.new.js index 32ddb28afa..31750e80ff 100644 --- a/packages/react-reconciler/src/ReactFiberHotReloading.new.js +++ b/packages/react-reconciler/src/ReactFiberHotReloading.new.js @@ -49,6 +49,7 @@ import { REACT_LAZY_TYPE, } from 'shared/ReactSymbols'; import {enableFloat} from 'shared/ReactFeatureFlags'; +import {DiscreteEventPriority} from './ReactEventPriorities'; let resolveFamily: RefreshHandler | null = null; let failedBoundaries: WeakSet | null = null; @@ -314,7 +315,13 @@ function scheduleFibersWithFamiliesRecursively( if (needsRemount || needsRender) { const root = enqueueConcurrentRenderForLane(fiber, SyncLane); if (root !== null) { - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp); + scheduleUpdateOnFiber( + root, + fiber, + SyncLane, + NoTimestamp, + DiscreteEventPriority, + ); } } if (child !== null && !needsRemount) { diff --git a/packages/react-reconciler/src/ReactFiberHotReloading.old.js b/packages/react-reconciler/src/ReactFiberHotReloading.old.js index 0b553eaad3..908e699918 100644 --- a/packages/react-reconciler/src/ReactFiberHotReloading.old.js +++ b/packages/react-reconciler/src/ReactFiberHotReloading.old.js @@ -49,6 +49,7 @@ import { REACT_LAZY_TYPE, } from 'shared/ReactSymbols'; import {enableFloat} from 'shared/ReactFeatureFlags'; +import {DiscreteEventPriority} from './ReactEventPriorities'; let resolveFamily: RefreshHandler | null = null; let failedBoundaries: WeakSet | null = null; @@ -314,7 +315,13 @@ function scheduleFibersWithFamiliesRecursively( if (needsRemount || needsRender) { const root = enqueueConcurrentRenderForLane(fiber, SyncLane); if (root !== null) { - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp); + scheduleUpdateOnFiber( + root, + fiber, + SyncLane, + NoTimestamp, + DiscreteEventPriority, + ); } } if (child !== null && !needsRemount) { diff --git a/packages/react-reconciler/src/ReactFiberLane.new.js b/packages/react-reconciler/src/ReactFiberLane.new.js index 36af3b95be..94d30268ed 100644 --- a/packages/react-reconciler/src/ReactFiberLane.new.js +++ b/packages/react-reconciler/src/ReactFiberLane.new.js @@ -10,6 +10,7 @@ import type {Fiber, FiberRoot} from './ReactInternalTypes'; import type {Transition} from './ReactFiberTracingMarkerComponent.new'; import type {ConcurrentUpdate} from './ReactFiberConcurrentUpdates.new'; +import type {EventPriority} from './ReactEventPriorities.new'; // TODO: Ideally these types would be opaque but that doesn't work well with // our reconciler fork infra, since these leak into non-reconciler packages. @@ -588,9 +589,11 @@ export function markRootUpdated( root: FiberRoot, updateLane: Lane, eventTime: number, + updatePriority: EventPriority, ) { root.pendingLanes |= updateLane; + root.updatePriority = updatePriority; // If there are any suspended transitions, it's possible this new update // could unblock them. Clear the suspended lanes so that we can try rendering // them again. diff --git a/packages/react-reconciler/src/ReactFiberLane.old.js b/packages/react-reconciler/src/ReactFiberLane.old.js index 38fe4700df..f817868c92 100644 --- a/packages/react-reconciler/src/ReactFiberLane.old.js +++ b/packages/react-reconciler/src/ReactFiberLane.old.js @@ -10,6 +10,7 @@ import type {Fiber, FiberRoot} from './ReactInternalTypes'; import type {Transition} from './ReactFiberTracingMarkerComponent.old'; import type {ConcurrentUpdate} from './ReactFiberConcurrentUpdates.old'; +import type {EventPriority} from './ReactEventPriorities.old'; // TODO: Ideally these types would be opaque but that doesn't work well with // our reconciler fork infra, since these leak into non-reconciler packages. @@ -588,9 +589,11 @@ export function markRootUpdated( root: FiberRoot, updateLane: Lane, eventTime: number, + updatePriority: EventPriority, ) { root.pendingLanes |= updateLane; + root.updatePriority = updatePriority; // If there are any suspended transitions, it's possible this new update // could unblock them. Clear the suspended lanes so that we can try rendering // them again. diff --git a/packages/react-reconciler/src/ReactFiberReconciler.new.js b/packages/react-reconciler/src/ReactFiberReconciler.new.js index 08ded0097b..9b5b342c98 100644 --- a/packages/react-reconciler/src/ReactFiberReconciler.new.js +++ b/packages/react-reconciler/src/ReactFiberReconciler.new.js @@ -67,6 +67,7 @@ import { deferredUpdates, discreteUpdates, flushPassiveEffects, + requestUpdateLane_getUpdatePriority, } from './ReactFiberWorkLoop.new'; import {enqueueConcurrentRenderForLane} from './ReactFiberConcurrentUpdates.new'; import { @@ -99,6 +100,10 @@ import { findHostInstancesForRefresh, } from './ReactFiberHotReloading.new'; import ReactVersion from 'shared/ReactVersion'; +import { + ContinuousEventPriority, + DiscreteEventPriority, +} from './ReactEventPriorities'; export {registerMutableSourceForHydration} from './ReactMutableSource.new'; export {createPortal} from './ReactPortal'; export { @@ -330,6 +335,7 @@ export function updateContainer( const current = container.current; const eventTime = requestEventTime(); const lane = requestUpdateLane(current); + const updatePriority = requestUpdateLane_getUpdatePriority(); if (enableSchedulingProfiler) { markRenderScheduled(lane); @@ -380,7 +386,7 @@ export function updateContainer( const root = enqueueUpdate(current, update, lane); if (root !== null) { - scheduleUpdateOnFiber(root, current, lane, eventTime); + scheduleUpdateOnFiber(root, current, lane, eventTime, updatePriority); entangleTransitions(root, current, lane); } @@ -428,7 +434,13 @@ export function attemptSynchronousHydration(fiber: Fiber): void { const root = enqueueConcurrentRenderForLane(fiber, SyncLane); if (root !== null) { const eventTime = requestEventTime(); - scheduleUpdateOnFiber(root, fiber, SyncLane, eventTime); + scheduleUpdateOnFiber( + root, + fiber, + SyncLane, + eventTime, + DiscreteEventPriority, + ); } }); // If we're still blocked after this, we need to increase @@ -472,7 +484,7 @@ export function attemptDiscreteHydration(fiber: Fiber): void { const root = enqueueConcurrentRenderForLane(fiber, lane); if (root !== null) { const eventTime = requestEventTime(); - scheduleUpdateOnFiber(root, fiber, lane, eventTime); + scheduleUpdateOnFiber(root, fiber, lane, eventTime, DiscreteEventPriority); } markRetryLaneIfNotHydrated(fiber, lane); } @@ -489,7 +501,13 @@ export function attemptContinuousHydration(fiber: Fiber): void { const root = enqueueConcurrentRenderForLane(fiber, lane); if (root !== null) { const eventTime = requestEventTime(); - scheduleUpdateOnFiber(root, fiber, lane, eventTime); + scheduleUpdateOnFiber( + root, + fiber, + lane, + eventTime, + ContinuousEventPriority, + ); } markRetryLaneIfNotHydrated(fiber, lane); } @@ -501,10 +519,11 @@ export function attemptHydrationAtCurrentPriority(fiber: Fiber): void { return; } const lane = requestUpdateLane(fiber); + const updatePriority = requestUpdateLane_getUpdatePriority(); const root = enqueueConcurrentRenderForLane(fiber, lane); if (root !== null) { const eventTime = requestEventTime(); - scheduleUpdateOnFiber(root, fiber, lane, eventTime); + scheduleUpdateOnFiber(root, fiber, lane, eventTime, updatePriority); } markRetryLaneIfNotHydrated(fiber, lane); } @@ -683,7 +702,13 @@ if (__DEV__) { const root = enqueueConcurrentRenderForLane(fiber, SyncLane); if (root !== null) { - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp); + scheduleUpdateOnFiber( + root, + fiber, + SyncLane, + NoTimestamp, + root.updatePriority, + ); } } }; @@ -707,7 +732,13 @@ if (__DEV__) { const root = enqueueConcurrentRenderForLane(fiber, SyncLane); if (root !== null) { - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp); + scheduleUpdateOnFiber( + root, + fiber, + SyncLane, + NoTimestamp, + root.updatePriority, + ); } } }; @@ -732,7 +763,13 @@ if (__DEV__) { const root = enqueueConcurrentRenderForLane(fiber, SyncLane); if (root !== null) { - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp); + scheduleUpdateOnFiber( + root, + fiber, + SyncLane, + NoTimestamp, + root.updatePriority, + ); } } }; @@ -745,7 +782,13 @@ if (__DEV__) { } const root = enqueueConcurrentRenderForLane(fiber, SyncLane); if (root !== null) { - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp); + scheduleUpdateOnFiber( + root, + fiber, + SyncLane, + NoTimestamp, + root.updatePriority, + ); } }; overridePropsDeletePath = (fiber: Fiber, path: Array) => { @@ -755,7 +798,13 @@ if (__DEV__) { } const root = enqueueConcurrentRenderForLane(fiber, SyncLane); if (root !== null) { - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp); + scheduleUpdateOnFiber( + root, + fiber, + SyncLane, + NoTimestamp, + root.updatePriority, + ); } }; overridePropsRenamePath = ( @@ -769,14 +818,26 @@ if (__DEV__) { } const root = enqueueConcurrentRenderForLane(fiber, SyncLane); if (root !== null) { - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp); + scheduleUpdateOnFiber( + root, + fiber, + SyncLane, + NoTimestamp, + root.updatePriority, + ); } }; scheduleUpdate = (fiber: Fiber) => { const root = enqueueConcurrentRenderForLane(fiber, SyncLane); if (root !== null) { - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp); + scheduleUpdateOnFiber( + root, + fiber, + SyncLane, + NoTimestamp, + root.updatePriority, + ); } }; diff --git a/packages/react-reconciler/src/ReactFiberReconciler.old.js b/packages/react-reconciler/src/ReactFiberReconciler.old.js index d71bf1c04b..c98eacea9c 100644 --- a/packages/react-reconciler/src/ReactFiberReconciler.old.js +++ b/packages/react-reconciler/src/ReactFiberReconciler.old.js @@ -67,6 +67,7 @@ import { deferredUpdates, discreteUpdates, flushPassiveEffects, + requestUpdateLane_getUpdatePriority, } from './ReactFiberWorkLoop.old'; import {enqueueConcurrentRenderForLane} from './ReactFiberConcurrentUpdates.old'; import { @@ -99,6 +100,10 @@ import { findHostInstancesForRefresh, } from './ReactFiberHotReloading.old'; import ReactVersion from 'shared/ReactVersion'; +import { + ContinuousEventPriority, + DiscreteEventPriority, +} from './ReactEventPriorities'; export {registerMutableSourceForHydration} from './ReactMutableSource.old'; export {createPortal} from './ReactPortal'; export { @@ -330,6 +335,7 @@ export function updateContainer( const current = container.current; const eventTime = requestEventTime(); const lane = requestUpdateLane(current); + const updatePriority = requestUpdateLane_getUpdatePriority(); if (enableSchedulingProfiler) { markRenderScheduled(lane); @@ -380,7 +386,7 @@ export function updateContainer( const root = enqueueUpdate(current, update, lane); if (root !== null) { - scheduleUpdateOnFiber(root, current, lane, eventTime); + scheduleUpdateOnFiber(root, current, lane, eventTime, updatePriority); entangleTransitions(root, current, lane); } @@ -428,7 +434,13 @@ export function attemptSynchronousHydration(fiber: Fiber): void { const root = enqueueConcurrentRenderForLane(fiber, SyncLane); if (root !== null) { const eventTime = requestEventTime(); - scheduleUpdateOnFiber(root, fiber, SyncLane, eventTime); + scheduleUpdateOnFiber( + root, + fiber, + SyncLane, + eventTime, + DiscreteEventPriority, + ); } }); // If we're still blocked after this, we need to increase @@ -472,7 +484,7 @@ export function attemptDiscreteHydration(fiber: Fiber): void { const root = enqueueConcurrentRenderForLane(fiber, lane); if (root !== null) { const eventTime = requestEventTime(); - scheduleUpdateOnFiber(root, fiber, lane, eventTime); + scheduleUpdateOnFiber(root, fiber, lane, eventTime, DiscreteEventPriority); } markRetryLaneIfNotHydrated(fiber, lane); } @@ -489,7 +501,13 @@ export function attemptContinuousHydration(fiber: Fiber): void { const root = enqueueConcurrentRenderForLane(fiber, lane); if (root !== null) { const eventTime = requestEventTime(); - scheduleUpdateOnFiber(root, fiber, lane, eventTime); + scheduleUpdateOnFiber( + root, + fiber, + lane, + eventTime, + ContinuousEventPriority, + ); } markRetryLaneIfNotHydrated(fiber, lane); } @@ -501,10 +519,11 @@ export function attemptHydrationAtCurrentPriority(fiber: Fiber): void { return; } const lane = requestUpdateLane(fiber); + const updatePriority = requestUpdateLane_getUpdatePriority(); const root = enqueueConcurrentRenderForLane(fiber, lane); if (root !== null) { const eventTime = requestEventTime(); - scheduleUpdateOnFiber(root, fiber, lane, eventTime); + scheduleUpdateOnFiber(root, fiber, lane, eventTime, updatePriority); } markRetryLaneIfNotHydrated(fiber, lane); } @@ -683,7 +702,13 @@ if (__DEV__) { const root = enqueueConcurrentRenderForLane(fiber, SyncLane); if (root !== null) { - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp); + scheduleUpdateOnFiber( + root, + fiber, + SyncLane, + NoTimestamp, + root.updatePriority, + ); } } }; @@ -707,7 +732,13 @@ if (__DEV__) { const root = enqueueConcurrentRenderForLane(fiber, SyncLane); if (root !== null) { - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp); + scheduleUpdateOnFiber( + root, + fiber, + SyncLane, + NoTimestamp, + root.updatePriority, + ); } } }; @@ -732,7 +763,13 @@ if (__DEV__) { const root = enqueueConcurrentRenderForLane(fiber, SyncLane); if (root !== null) { - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp); + scheduleUpdateOnFiber( + root, + fiber, + SyncLane, + NoTimestamp, + root.updatePriority, + ); } } }; @@ -745,7 +782,13 @@ if (__DEV__) { } const root = enqueueConcurrentRenderForLane(fiber, SyncLane); if (root !== null) { - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp); + scheduleUpdateOnFiber( + root, + fiber, + SyncLane, + NoTimestamp, + root.updatePriority, + ); } }; overridePropsDeletePath = (fiber: Fiber, path: Array) => { @@ -755,7 +798,13 @@ if (__DEV__) { } const root = enqueueConcurrentRenderForLane(fiber, SyncLane); if (root !== null) { - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp); + scheduleUpdateOnFiber( + root, + fiber, + SyncLane, + NoTimestamp, + root.updatePriority, + ); } }; overridePropsRenamePath = ( @@ -769,14 +818,26 @@ if (__DEV__) { } const root = enqueueConcurrentRenderForLane(fiber, SyncLane); if (root !== null) { - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp); + scheduleUpdateOnFiber( + root, + fiber, + SyncLane, + NoTimestamp, + root.updatePriority, + ); } }; scheduleUpdate = (fiber: Fiber) => { const root = enqueueConcurrentRenderForLane(fiber, SyncLane); if (root !== null) { - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp); + scheduleUpdateOnFiber( + root, + fiber, + SyncLane, + NoTimestamp, + root.updatePriority, + ); } }; diff --git a/packages/react-reconciler/src/ReactFiberRoot.new.js b/packages/react-reconciler/src/ReactFiberRoot.new.js index ea63422341..3378ed9da8 100644 --- a/packages/react-reconciler/src/ReactFiberRoot.new.js +++ b/packages/react-reconciler/src/ReactFiberRoot.new.js @@ -62,6 +62,7 @@ function FiberRootNode( this.pendingContext = null; this.callbackNode = null; this.callbackPriority = NoEventPriority; + this.updatePriority = NoEventPriority; this.eventTimes = createLaneMap(NoLanes); this.expirationTimes = createLaneMap(NoTimestamp); diff --git a/packages/react-reconciler/src/ReactFiberRoot.old.js b/packages/react-reconciler/src/ReactFiberRoot.old.js index ffb8526844..47c0b7c0c7 100644 --- a/packages/react-reconciler/src/ReactFiberRoot.old.js +++ b/packages/react-reconciler/src/ReactFiberRoot.old.js @@ -62,6 +62,7 @@ function FiberRootNode( this.pendingContext = null; this.callbackNode = null; this.callbackPriority = NoEventPriority; + this.updatePriority = NoEventPriority; this.eventTimes = createLaneMap(NoLanes); this.expirationTimes = createLaneMap(NoTimestamp); diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js index ccd1023da5..1a93e722b3 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js @@ -603,10 +603,18 @@ export function getCurrentTime(): number { return now(); } +let currentUpdatePriority = NoEventPriority; + +export function requestUpdateLane_getUpdatePriority(): EventPriority { + return currentUpdatePriority; +} + export function requestUpdateLane(fiber: Fiber): Lane { + currentUpdatePriority = NoEventPriority; // Special cases const mode = fiber.mode; if ((mode & ConcurrentMode) === NoMode) { + currentUpdatePriority = DiscreteEventPriority; return (SyncLane: Lane); } else if ( !deferRenderPhaseUpdateToNextBatch && @@ -655,6 +663,7 @@ export function requestUpdateLane(fiber: Fiber): Lane { // TODO: Move this type conversion to the event priority module. const updatePriority = getCurrentUpdatePriority(); if (updatePriority !== NoEventPriority) { + currentUpdatePriority = updatePriority; if (updatePriority === DefaultEventPriority) { return DefaultLane; } @@ -669,6 +678,7 @@ export function requestUpdateLane(fiber: Fiber): Lane { // // TODO: Move this type conversion to the event priority module. const eventPriority = getCurrentEventPriority(); + currentUpdatePriority = eventPriority; if (eventPriority === DefaultEventPriority) { return DefaultLane; } @@ -697,6 +707,7 @@ export function scheduleUpdateOnFiber( fiber: Fiber, lane: Lane, eventTime: number, + updatePriority: EventPriority, ) { if (__DEV__) { if (isRunningInsertionEffect) { @@ -711,7 +722,7 @@ export function scheduleUpdateOnFiber( } // Mark that the root has a pending update. - markRootUpdated(root, lane, eventTime); + markRootUpdated(root, lane, eventTime, updatePriority); if ( (executionContext & RenderContext) !== NoLanes && @@ -832,7 +843,7 @@ export function scheduleInitialHydrationOnRoot( // match what was rendered on the server. const current = root.current; current.lanes = lane; - markRootUpdated(root, lane, eventTime); + markRootUpdated(root, lane, eventTime, root.updatePriority); ensureRootIsScheduled(root, eventTime); } @@ -2651,6 +2662,7 @@ function commitRootImpl( // are consolidated. if ( includesSomeLane(pendingPassiveEffectsLanes, SyncLane) && + root.updatePriority === DiscreteEventPriority && root.tag !== LegacyRoot ) { flushPassiveEffects(); @@ -2965,7 +2977,7 @@ function captureCommitPhaseErrorOnRoot( const root = enqueueUpdate(rootFiber, update, (SyncLane: Lane)); const eventTime = requestEventTime(); if (root !== null) { - markRootUpdated(root, SyncLane, eventTime); + markRootUpdated(root, SyncLane, eventTime, DiscreteEventPriority); ensureRootIsScheduled(root, eventTime); } } @@ -3014,7 +3026,7 @@ export function captureCommitPhaseError( const root = enqueueUpdate(fiber, update, (SyncLane: Lane)); const eventTime = requestEventTime(); if (root !== null) { - markRootUpdated(root, SyncLane, eventTime); + markRootUpdated(root, SyncLane, eventTime, DiscreteEventPriority); ensureRootIsScheduled(root, eventTime); } return; @@ -3150,7 +3162,7 @@ function retryTimedOutBoundary(boundaryFiber: Fiber, retryLane: Lane) { const eventTime = requestEventTime(); const root = enqueueConcurrentRenderForLane(boundaryFiber, retryLane); if (root !== null) { - markRootUpdated(root, retryLane, eventTime); + markRootUpdated(root, retryLane, eventTime, root.updatePriority); ensureRootIsScheduled(root, eventTime); } } diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js index 682aa63b55..a279c1f4c2 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js @@ -603,10 +603,18 @@ export function getCurrentTime(): number { return now(); } +let currentUpdatePriority = NoEventPriority; + +export function requestUpdateLane_getUpdatePriority(): EventPriority { + return currentUpdatePriority; +} + export function requestUpdateLane(fiber: Fiber): Lane { + currentUpdatePriority = NoEventPriority; // Special cases const mode = fiber.mode; if ((mode & ConcurrentMode) === NoMode) { + currentUpdatePriority = DiscreteEventPriority; return (SyncLane: Lane); } else if ( !deferRenderPhaseUpdateToNextBatch && @@ -655,6 +663,7 @@ export function requestUpdateLane(fiber: Fiber): Lane { // TODO: Move this type conversion to the event priority module. const updatePriority = getCurrentUpdatePriority(); if (updatePriority !== NoEventPriority) { + currentUpdatePriority = updatePriority; if (updatePriority === DefaultEventPriority) { return DefaultLane; } @@ -669,6 +678,7 @@ export function requestUpdateLane(fiber: Fiber): Lane { // // TODO: Move this type conversion to the event priority module. const eventPriority = getCurrentEventPriority(); + currentUpdatePriority = eventPriority; if (eventPriority === DefaultEventPriority) { return DefaultLane; } @@ -697,6 +707,7 @@ export function scheduleUpdateOnFiber( fiber: Fiber, lane: Lane, eventTime: number, + updatePriority: EventPriority, ) { if (__DEV__) { if (isRunningInsertionEffect) { @@ -711,7 +722,7 @@ export function scheduleUpdateOnFiber( } // Mark that the root has a pending update. - markRootUpdated(root, lane, eventTime); + markRootUpdated(root, lane, eventTime, updatePriority); if ( (executionContext & RenderContext) !== NoLanes && @@ -832,7 +843,7 @@ export function scheduleInitialHydrationOnRoot( // match what was rendered on the server. const current = root.current; current.lanes = lane; - markRootUpdated(root, lane, eventTime); + markRootUpdated(root, lane, eventTime, root.updatePriority); ensureRootIsScheduled(root, eventTime); } @@ -2651,6 +2662,7 @@ function commitRootImpl( // are consolidated. if ( includesSomeLane(pendingPassiveEffectsLanes, SyncLane) && + root.updatePriority === DiscreteEventPriority && root.tag !== LegacyRoot ) { flushPassiveEffects(); @@ -2965,7 +2977,7 @@ function captureCommitPhaseErrorOnRoot( const root = enqueueUpdate(rootFiber, update, (SyncLane: Lane)); const eventTime = requestEventTime(); if (root !== null) { - markRootUpdated(root, SyncLane, eventTime); + markRootUpdated(root, SyncLane, eventTime, DiscreteEventPriority); ensureRootIsScheduled(root, eventTime); } } @@ -3014,7 +3026,7 @@ export function captureCommitPhaseError( const root = enqueueUpdate(fiber, update, (SyncLane: Lane)); const eventTime = requestEventTime(); if (root !== null) { - markRootUpdated(root, SyncLane, eventTime); + markRootUpdated(root, SyncLane, eventTime, DiscreteEventPriority); ensureRootIsScheduled(root, eventTime); } return; @@ -3150,7 +3162,7 @@ function retryTimedOutBoundary(boundaryFiber: Fiber, retryLane: Lane) { const eventTime = requestEventTime(); const root = enqueueConcurrentRenderForLane(boundaryFiber, retryLane); if (root !== null) { - markRootUpdated(root, retryLane, eventTime); + markRootUpdated(root, retryLane, eventTime, root.updatePriority); ensureRootIsScheduled(root, eventTime); } } diff --git a/packages/react-reconciler/src/ReactInternalTypes.js b/packages/react-reconciler/src/ReactInternalTypes.js index 5751e00a21..2b904acd0d 100644 --- a/packages/react-reconciler/src/ReactInternalTypes.js +++ b/packages/react-reconciler/src/ReactInternalTypes.js @@ -241,6 +241,7 @@ type BaseFiberRootProperties = { // task that the root will work on. callbackNode: any, callbackPriority: EventPriority, + updatePriority: EventPriority, eventTimes: LaneMap, expirationTimes: LaneMap, hiddenUpdates: LaneMap | null>,