Skip to content

Commit

Permalink
[Fiber] Move updatePriority tracking to renderers (#28751)
Browse files Browse the repository at this point in the history
Currently updatePriority is tracked in the reconciler. `flushSync` is
going to be implemented reconciler agnostic soon and we need to move the
tracking of this state to the renderer and out of reconciler. This
change implements new renderer bin dings for getCurrentUpdatePriority
and setCurrentUpdatePriority.

I was originally going to have the getter also do the event priority
defaulting using window.event so we eliminate getCur rentEventPriority
but this makes all the callsites where we store the true current
updatePriority on the stack harder to work with so for now they remain
separate.

I also moved runWithPriority to the renderer since it really belongs
whereever the state is being managed and it is only currently exposed in
the DOM renderer.

Additionally the current update priority is not stored on
ReactDOMSharedInternals. While not particularly meaningful in this
change it opens the door to implementing `flushSync` outside of the
reconciler

DiffTrain build for [8e1462e](8e1462e)
  • Loading branch information
gnoff committed Apr 8, 2024
1 parent aabb356 commit ffde2c0
Show file tree
Hide file tree
Showing 17 changed files with 5,384 additions and 5,449 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0b3b8a6a354b90fe76a9d82bb34487e5d2f71203
8e1462e8c471fbec98aac2b3e1326498d0ff7139
53 changes: 20 additions & 33 deletions compiled/facebook-www/ReactART-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ if (__DEV__) {
return self;
}

var ReactVersion = "19.0.0-www-classic-fcdce517";
var ReactVersion = "19.0.0-www-classic-6d726b4b";

var LegacyRoot = 0;
var ConcurrentRoot = 1;
Expand Down Expand Up @@ -2576,17 +2576,11 @@ if (__DEV__) {
}
}

var NoEventPriority = NoLane;
var DiscreteEventPriority = SyncLane;
var ContinuousEventPriority = InputContinuousLane;
var DefaultEventPriority = DefaultLane;
var IdleEventPriority = IdleLane;
var currentUpdatePriority = NoLane;
function getCurrentUpdatePriority() {
return currentUpdatePriority;
}
function setCurrentUpdatePriority(newPriority) {
currentUpdatePriority = newPriority;
}
function higherEventPriority(a, b) {
return a !== 0 && a < b ? a : b;
}
Expand All @@ -2596,6 +2590,9 @@ if (__DEV__) {
function isHigherEventPriority(a, b) {
return a !== 0 && a < b;
}
function eventPriorityToLane(updatePriority) {
return updatePriority;
}
function lanesToEventPriority(lanes) {
var lane = getHighestPriorityLane(lanes);

Expand Down Expand Up @@ -2961,8 +2958,15 @@ if (__DEV__) {
typeof props.children === "string" || typeof props.children === "number"
);
}
function getCurrentEventPriority() {
return DefaultEventPriority;
var currentUpdatePriority = NoEventPriority;
function setCurrentUpdatePriority(newPriority) {
currentUpdatePriority = newPriority;
}
function getCurrentUpdatePriority() {
return currentUpdatePriority;
}
function resolveUpdatePriority() {
return currentUpdatePriority || DefaultEventPriority;
}
function shouldAttemptEagerTransition() {
return false;
Expand Down Expand Up @@ -25880,26 +25884,9 @@ if (__DEV__) {
: // is the first update in that scope. Either way, we need to get a
// fresh transition lane.
requestTransitionLane();
} // Updates originating inside certain React methods, like flushSync, have
// their priority set by tracking it with a context variable.
//
// The opaque type returned by the host config is internally a lane, so we can
// use that directly.
// TODO: Move this type conversion to the event priority module.

var updateLane = getCurrentUpdatePriority();

if (updateLane !== NoLane) {
return updateLane;
} // This update originated outside React. Ask the host environment for an
// appropriate priority, based on the type of event.
//
// The opaque type returned by the host config is internally a lane, so we can
// use that directly.
// TODO: Move this type conversion to the event priority module.
}

var eventLane = getCurrentEventPriority();
return eventLane;
return eventPriorityToLane(resolveUpdatePriority());
}

function requestRetryLane(fiber) {
Expand Down Expand Up @@ -26633,8 +26620,8 @@ if (__DEV__) {
var previousPriority = getCurrentUpdatePriority();

try {
ReactCurrentBatchConfig.transition = null;
setCurrentUpdatePriority(DiscreteEventPriority);
ReactCurrentBatchConfig.transition = null;

if (fn) {
return fn();
Expand Down Expand Up @@ -27801,12 +27788,12 @@ if (__DEV__) {
) {
// TODO: This no longer makes any sense. We already wrap the mutation and
// layout phases. Should be able to remove.
var previousUpdateLanePriority = getCurrentUpdatePriority();
var prevTransition = ReactCurrentBatchConfig.transition;
var previousUpdateLanePriority = getCurrentUpdatePriority();

try {
ReactCurrentBatchConfig.transition = null;
setCurrentUpdatePriority(DiscreteEventPriority);
ReactCurrentBatchConfig.transition = null;
commitRootImpl(
root,
recoverableErrors,
Expand Down Expand Up @@ -28212,8 +28199,8 @@ if (__DEV__) {
var previousPriority = getCurrentUpdatePriority();

try {
ReactCurrentBatchConfig.transition = null;
setCurrentUpdatePriority(priority);
ReactCurrentBatchConfig.transition = null;
return flushPassiveEffectsImpl();
} finally {
setCurrentUpdatePriority(previousPriority);
Expand Down
53 changes: 20 additions & 33 deletions compiled/facebook-www/ReactART-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ if (__DEV__) {
return self;
}

var ReactVersion = "19.0.0-www-modern-f3bc72db";
var ReactVersion = "19.0.0-www-modern-35717797";

var LegacyRoot = 0;
var ConcurrentRoot = 1;
Expand Down Expand Up @@ -2573,17 +2573,11 @@ if (__DEV__) {
}
}

var NoEventPriority = NoLane;
var DiscreteEventPriority = SyncLane;
var ContinuousEventPriority = InputContinuousLane;
var DefaultEventPriority = DefaultLane;
var IdleEventPriority = IdleLane;
var currentUpdatePriority = NoLane;
function getCurrentUpdatePriority() {
return currentUpdatePriority;
}
function setCurrentUpdatePriority(newPriority) {
currentUpdatePriority = newPriority;
}
function higherEventPriority(a, b) {
return a !== 0 && a < b ? a : b;
}
Expand All @@ -2593,6 +2587,9 @@ if (__DEV__) {
function isHigherEventPriority(a, b) {
return a !== 0 && a < b;
}
function eventPriorityToLane(updatePriority) {
return updatePriority;
}
function lanesToEventPriority(lanes) {
var lane = getHighestPriorityLane(lanes);

Expand Down Expand Up @@ -2958,8 +2955,15 @@ if (__DEV__) {
typeof props.children === "string" || typeof props.children === "number"
);
}
function getCurrentEventPriority() {
return DefaultEventPriority;
var currentUpdatePriority = NoEventPriority;
function setCurrentUpdatePriority(newPriority) {
currentUpdatePriority = newPriority;
}
function getCurrentUpdatePriority() {
return currentUpdatePriority;
}
function resolveUpdatePriority() {
return currentUpdatePriority || DefaultEventPriority;
}
function shouldAttemptEagerTransition() {
return false;
Expand Down Expand Up @@ -25098,26 +25102,9 @@ if (__DEV__) {
: // is the first update in that scope. Either way, we need to get a
// fresh transition lane.
requestTransitionLane();
} // Updates originating inside certain React methods, like flushSync, have
// their priority set by tracking it with a context variable.
//
// The opaque type returned by the host config is internally a lane, so we can
// use that directly.
// TODO: Move this type conversion to the event priority module.

var updateLane = getCurrentUpdatePriority();

if (updateLane !== NoLane) {
return updateLane;
} // This update originated outside React. Ask the host environment for an
// appropriate priority, based on the type of event.
//
// The opaque type returned by the host config is internally a lane, so we can
// use that directly.
// TODO: Move this type conversion to the event priority module.
}

var eventLane = getCurrentEventPriority();
return eventLane;
return eventPriorityToLane(resolveUpdatePriority());
}

function requestRetryLane(fiber) {
Expand Down Expand Up @@ -25840,8 +25827,8 @@ if (__DEV__) {
var previousPriority = getCurrentUpdatePriority();

try {
ReactCurrentBatchConfig.transition = null;
setCurrentUpdatePriority(DiscreteEventPriority);
ReactCurrentBatchConfig.transition = null;

if (fn) {
return fn();
Expand Down Expand Up @@ -26999,12 +26986,12 @@ if (__DEV__) {
) {
// TODO: This no longer makes any sense. We already wrap the mutation and
// layout phases. Should be able to remove.
var previousUpdateLanePriority = getCurrentUpdatePriority();
var prevTransition = ReactCurrentBatchConfig.transition;
var previousUpdateLanePriority = getCurrentUpdatePriority();

try {
ReactCurrentBatchConfig.transition = null;
setCurrentUpdatePriority(DiscreteEventPriority);
ReactCurrentBatchConfig.transition = null;
commitRootImpl(
root,
recoverableErrors,
Expand Down Expand Up @@ -27407,8 +27394,8 @@ if (__DEV__) {
var previousPriority = getCurrentUpdatePriority();

try {
ReactCurrentBatchConfig.transition = null;
setCurrentUpdatePriority(priority);
ReactCurrentBatchConfig.transition = null;
return flushPassiveEffectsImpl();
} finally {
setCurrentUpdatePriority(previousPriority);
Expand Down
45 changes: 21 additions & 24 deletions compiled/facebook-www/ReactART-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,6 @@ function clearTransitionsForLanes(root, lanes) {
lanes &= ~lane;
}
}
var currentUpdatePriority = 0;
function lanesToEventPriority(lanes) {
lanes &= -lanes;
return 2 < lanes
Expand Down Expand Up @@ -826,7 +825,8 @@ function shouldSetTextContent(type, props) {
"string" === typeof props.children || "number" === typeof props.children
);
}
var valueStack = [],
var currentUpdatePriority = 0,
valueStack = [],
index = -1;
function createCursor(defaultValue) {
return { current: defaultValue };
Expand Down Expand Up @@ -8998,16 +8998,14 @@ var legacyErrorBoundariesThatAlreadyFailed = null,
nestedUpdateCount = 0,
rootWithNestedUpdates = null;
function requestUpdateLane(fiber) {
if (0 === (fiber.mode & 1)) return 2;
if (0 !== (executionContext & 2) && 0 !== workInProgressRootRenderLanes)
return workInProgressRootRenderLanes & -workInProgressRootRenderLanes;
if (null !== requestCurrentTransition())
return (
(fiber = currentEntangledLane),
0 !== fiber ? fiber : requestTransitionLane()
);
fiber = currentUpdatePriority;
return 0 !== fiber ? fiber : 32;
return 0 === (fiber.mode & 1)
? 2
: 0 !== (executionContext & 2) && 0 !== workInProgressRootRenderLanes
? workInProgressRootRenderLanes & -workInProgressRootRenderLanes
: null !== requestCurrentTransition()
? ((fiber = currentEntangledLane),
0 !== fiber ? fiber : requestTransitionLane())
: currentUpdatePriority || 32;
}
function requestDeferredLane() {
0 === workInProgressDeferredLane &&
Expand Down Expand Up @@ -9352,8 +9350,8 @@ function flushSync(fn) {
previousPriority = currentUpdatePriority;
try {
if (
((ReactCurrentBatchConfig.transition = null),
(currentUpdatePriority = 2),
((currentUpdatePriority = 2),
(ReactCurrentBatchConfig.transition = null),
fn)
)
return fn();
Expand Down Expand Up @@ -9787,11 +9785,11 @@ function commitRoot(
didIncludeRenderPhaseUpdate,
spawnedLane
) {
var previousUpdateLanePriority = currentUpdatePriority,
prevTransition = ReactCurrentBatchConfig.transition;
var prevTransition = ReactCurrentBatchConfig.transition,
previousUpdateLanePriority = currentUpdatePriority;
try {
(ReactCurrentBatchConfig.transition = null),
(currentUpdatePriority = 2),
(currentUpdatePriority = 2),
(ReactCurrentBatchConfig.transition = null),
commitRootImpl(
root,
recoverableErrors,
Expand Down Expand Up @@ -9905,14 +9903,13 @@ function flushPassiveEffects() {
var root = rootWithPendingPassiveEffects,
remainingLanes = pendingPassiveEffectsRemainingLanes;
pendingPassiveEffectsRemainingLanes = 0;
var renderPriority = lanesToEventPriority(pendingPassiveEffectsLanes);
renderPriority = 32 > renderPriority ? 32 : renderPriority;
var prevTransition = ReactCurrentBatchConfig.transition,
var renderPriority = lanesToEventPriority(pendingPassiveEffectsLanes),
prevTransition = ReactCurrentBatchConfig.transition,
previousPriority = currentUpdatePriority;
try {
return (
(currentUpdatePriority = 32 > renderPriority ? 32 : renderPriority),
(ReactCurrentBatchConfig.transition = null),
(currentUpdatePriority = renderPriority),
flushPassiveEffectsImpl()
);
} finally {
Expand Down Expand Up @@ -10657,7 +10654,7 @@ var slice = Array.prototype.slice,
return null;
},
bundleType: 0,
version: "19.0.0-www-classic-2b02e6e9",
version: "19.0.0-www-classic-ce2e7147",
rendererPackageName: "react-art"
};
var internals$jscomp$inline_1315 = {
Expand Down Expand Up @@ -10688,7 +10685,7 @@ var internals$jscomp$inline_1315 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "19.0.0-www-classic-2b02e6e9"
reconcilerVersion: "19.0.0-www-classic-ce2e7147"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1316 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Loading

0 comments on commit ffde2c0

Please sign in to comment.