Skip to content

Commit ffde2c0

Browse files
committed
[Fiber] Move updatePriority tracking to renderers (#28751)
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)
1 parent aabb356 commit ffde2c0

17 files changed

Lines changed: 5384 additions & 5449 deletions

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0b3b8a6a354b90fe76a9d82bb34487e5d2f71203
1+
8e1462e8c471fbec98aac2b3e1326498d0ff7139

compiled/facebook-www/ReactART-dev.classic.js

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ if (__DEV__) {
6666
return self;
6767
}
6868

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

7171
var LegacyRoot = 0;
7272
var ConcurrentRoot = 1;
@@ -2576,17 +2576,11 @@ if (__DEV__) {
25762576
}
25772577
}
25782578

2579+
var NoEventPriority = NoLane;
25792580
var DiscreteEventPriority = SyncLane;
25802581
var ContinuousEventPriority = InputContinuousLane;
25812582
var DefaultEventPriority = DefaultLane;
25822583
var IdleEventPriority = IdleLane;
2583-
var currentUpdatePriority = NoLane;
2584-
function getCurrentUpdatePriority() {
2585-
return currentUpdatePriority;
2586-
}
2587-
function setCurrentUpdatePriority(newPriority) {
2588-
currentUpdatePriority = newPriority;
2589-
}
25902584
function higherEventPriority(a, b) {
25912585
return a !== 0 && a < b ? a : b;
25922586
}
@@ -2596,6 +2590,9 @@ if (__DEV__) {
25962590
function isHigherEventPriority(a, b) {
25972591
return a !== 0 && a < b;
25982592
}
2593+
function eventPriorityToLane(updatePriority) {
2594+
return updatePriority;
2595+
}
25992596
function lanesToEventPriority(lanes) {
26002597
var lane = getHighestPriorityLane(lanes);
26012598

@@ -2961,8 +2958,15 @@ if (__DEV__) {
29612958
typeof props.children === "string" || typeof props.children === "number"
29622959
);
29632960
}
2964-
function getCurrentEventPriority() {
2965-
return DefaultEventPriority;
2961+
var currentUpdatePriority = NoEventPriority;
2962+
function setCurrentUpdatePriority(newPriority) {
2963+
currentUpdatePriority = newPriority;
2964+
}
2965+
function getCurrentUpdatePriority() {
2966+
return currentUpdatePriority;
2967+
}
2968+
function resolveUpdatePriority() {
2969+
return currentUpdatePriority || DefaultEventPriority;
29662970
}
29672971
function shouldAttemptEagerTransition() {
29682972
return false;
@@ -25880,26 +25884,9 @@ if (__DEV__) {
2588025884
: // is the first update in that scope. Either way, we need to get a
2588125885
// fresh transition lane.
2588225886
requestTransitionLane();
25883-
} // Updates originating inside certain React methods, like flushSync, have
25884-
// their priority set by tracking it with a context variable.
25885-
//
25886-
// The opaque type returned by the host config is internally a lane, so we can
25887-
// use that directly.
25888-
// TODO: Move this type conversion to the event priority module.
25889-
25890-
var updateLane = getCurrentUpdatePriority();
25891-
25892-
if (updateLane !== NoLane) {
25893-
return updateLane;
25894-
} // This update originated outside React. Ask the host environment for an
25895-
// appropriate priority, based on the type of event.
25896-
//
25897-
// The opaque type returned by the host config is internally a lane, so we can
25898-
// use that directly.
25899-
// TODO: Move this type conversion to the event priority module.
25887+
}
2590025888

25901-
var eventLane = getCurrentEventPriority();
25902-
return eventLane;
25889+
return eventPriorityToLane(resolveUpdatePriority());
2590325890
}
2590425891

2590525892
function requestRetryLane(fiber) {
@@ -26633,8 +26620,8 @@ if (__DEV__) {
2663326620
var previousPriority = getCurrentUpdatePriority();
2663426621

2663526622
try {
26636-
ReactCurrentBatchConfig.transition = null;
2663726623
setCurrentUpdatePriority(DiscreteEventPriority);
26624+
ReactCurrentBatchConfig.transition = null;
2663826625

2663926626
if (fn) {
2664026627
return fn();
@@ -27801,12 +27788,12 @@ if (__DEV__) {
2780127788
) {
2780227789
// TODO: This no longer makes any sense. We already wrap the mutation and
2780327790
// layout phases. Should be able to remove.
27804-
var previousUpdateLanePriority = getCurrentUpdatePriority();
2780527791
var prevTransition = ReactCurrentBatchConfig.transition;
27792+
var previousUpdateLanePriority = getCurrentUpdatePriority();
2780627793

2780727794
try {
27808-
ReactCurrentBatchConfig.transition = null;
2780927795
setCurrentUpdatePriority(DiscreteEventPriority);
27796+
ReactCurrentBatchConfig.transition = null;
2781027797
commitRootImpl(
2781127798
root,
2781227799
recoverableErrors,
@@ -28212,8 +28199,8 @@ if (__DEV__) {
2821228199
var previousPriority = getCurrentUpdatePriority();
2821328200

2821428201
try {
28215-
ReactCurrentBatchConfig.transition = null;
2821628202
setCurrentUpdatePriority(priority);
28203+
ReactCurrentBatchConfig.transition = null;
2821728204
return flushPassiveEffectsImpl();
2821828205
} finally {
2821928206
setCurrentUpdatePriority(previousPriority);

compiled/facebook-www/ReactART-dev.modern.js

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ if (__DEV__) {
6666
return self;
6767
}
6868

69-
var ReactVersion = "19.0.0-www-modern-f3bc72db";
69+
var ReactVersion = "19.0.0-www-modern-35717797";
7070

7171
var LegacyRoot = 0;
7272
var ConcurrentRoot = 1;
@@ -2573,17 +2573,11 @@ if (__DEV__) {
25732573
}
25742574
}
25752575

2576+
var NoEventPriority = NoLane;
25762577
var DiscreteEventPriority = SyncLane;
25772578
var ContinuousEventPriority = InputContinuousLane;
25782579
var DefaultEventPriority = DefaultLane;
25792580
var IdleEventPriority = IdleLane;
2580-
var currentUpdatePriority = NoLane;
2581-
function getCurrentUpdatePriority() {
2582-
return currentUpdatePriority;
2583-
}
2584-
function setCurrentUpdatePriority(newPriority) {
2585-
currentUpdatePriority = newPriority;
2586-
}
25872581
function higherEventPriority(a, b) {
25882582
return a !== 0 && a < b ? a : b;
25892583
}
@@ -2593,6 +2587,9 @@ if (__DEV__) {
25932587
function isHigherEventPriority(a, b) {
25942588
return a !== 0 && a < b;
25952589
}
2590+
function eventPriorityToLane(updatePriority) {
2591+
return updatePriority;
2592+
}
25962593
function lanesToEventPriority(lanes) {
25972594
var lane = getHighestPriorityLane(lanes);
25982595

@@ -2958,8 +2955,15 @@ if (__DEV__) {
29582955
typeof props.children === "string" || typeof props.children === "number"
29592956
);
29602957
}
2961-
function getCurrentEventPriority() {
2962-
return DefaultEventPriority;
2958+
var currentUpdatePriority = NoEventPriority;
2959+
function setCurrentUpdatePriority(newPriority) {
2960+
currentUpdatePriority = newPriority;
2961+
}
2962+
function getCurrentUpdatePriority() {
2963+
return currentUpdatePriority;
2964+
}
2965+
function resolveUpdatePriority() {
2966+
return currentUpdatePriority || DefaultEventPriority;
29632967
}
29642968
function shouldAttemptEagerTransition() {
29652969
return false;
@@ -25098,26 +25102,9 @@ if (__DEV__) {
2509825102
: // is the first update in that scope. Either way, we need to get a
2509925103
// fresh transition lane.
2510025104
requestTransitionLane();
25101-
} // Updates originating inside certain React methods, like flushSync, have
25102-
// their priority set by tracking it with a context variable.
25103-
//
25104-
// The opaque type returned by the host config is internally a lane, so we can
25105-
// use that directly.
25106-
// TODO: Move this type conversion to the event priority module.
25107-
25108-
var updateLane = getCurrentUpdatePriority();
25109-
25110-
if (updateLane !== NoLane) {
25111-
return updateLane;
25112-
} // This update originated outside React. Ask the host environment for an
25113-
// appropriate priority, based on the type of event.
25114-
//
25115-
// The opaque type returned by the host config is internally a lane, so we can
25116-
// use that directly.
25117-
// TODO: Move this type conversion to the event priority module.
25105+
}
2511825106

25119-
var eventLane = getCurrentEventPriority();
25120-
return eventLane;
25107+
return eventPriorityToLane(resolveUpdatePriority());
2512125108
}
2512225109

2512325110
function requestRetryLane(fiber) {
@@ -25840,8 +25827,8 @@ if (__DEV__) {
2584025827
var previousPriority = getCurrentUpdatePriority();
2584125828

2584225829
try {
25843-
ReactCurrentBatchConfig.transition = null;
2584425830
setCurrentUpdatePriority(DiscreteEventPriority);
25831+
ReactCurrentBatchConfig.transition = null;
2584525832

2584625833
if (fn) {
2584725834
return fn();
@@ -26999,12 +26986,12 @@ if (__DEV__) {
2699926986
) {
2700026987
// TODO: This no longer makes any sense. We already wrap the mutation and
2700126988
// layout phases. Should be able to remove.
27002-
var previousUpdateLanePriority = getCurrentUpdatePriority();
2700326989
var prevTransition = ReactCurrentBatchConfig.transition;
26990+
var previousUpdateLanePriority = getCurrentUpdatePriority();
2700426991

2700526992
try {
27006-
ReactCurrentBatchConfig.transition = null;
2700726993
setCurrentUpdatePriority(DiscreteEventPriority);
26994+
ReactCurrentBatchConfig.transition = null;
2700826995
commitRootImpl(
2700926996
root,
2701026997
recoverableErrors,
@@ -27407,8 +27394,8 @@ if (__DEV__) {
2740727394
var previousPriority = getCurrentUpdatePriority();
2740827395

2740927396
try {
27410-
ReactCurrentBatchConfig.transition = null;
2741127397
setCurrentUpdatePriority(priority);
27398+
ReactCurrentBatchConfig.transition = null;
2741227399
return flushPassiveEffectsImpl();
2741327400
} finally {
2741427401
setCurrentUpdatePriority(previousPriority);

compiled/facebook-www/ReactART-prod.classic.js

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,6 @@ function clearTransitionsForLanes(root, lanes) {
648648
lanes &= ~lane;
649649
}
650650
}
651-
var currentUpdatePriority = 0;
652651
function lanesToEventPriority(lanes) {
653652
lanes &= -lanes;
654653
return 2 < lanes
@@ -826,7 +825,8 @@ function shouldSetTextContent(type, props) {
826825
"string" === typeof props.children || "number" === typeof props.children
827826
);
828827
}
829-
var valueStack = [],
828+
var currentUpdatePriority = 0,
829+
valueStack = [],
830830
index = -1;
831831
function createCursor(defaultValue) {
832832
return { current: defaultValue };
@@ -8998,16 +8998,14 @@ var legacyErrorBoundariesThatAlreadyFailed = null,
89988998
nestedUpdateCount = 0,
89998999
rootWithNestedUpdates = null;
90009000
function requestUpdateLane(fiber) {
9001-
if (0 === (fiber.mode & 1)) return 2;
9002-
if (0 !== (executionContext & 2) && 0 !== workInProgressRootRenderLanes)
9003-
return workInProgressRootRenderLanes & -workInProgressRootRenderLanes;
9004-
if (null !== requestCurrentTransition())
9005-
return (
9006-
(fiber = currentEntangledLane),
9007-
0 !== fiber ? fiber : requestTransitionLane()
9008-
);
9009-
fiber = currentUpdatePriority;
9010-
return 0 !== fiber ? fiber : 32;
9001+
return 0 === (fiber.mode & 1)
9002+
? 2
9003+
: 0 !== (executionContext & 2) && 0 !== workInProgressRootRenderLanes
9004+
? workInProgressRootRenderLanes & -workInProgressRootRenderLanes
9005+
: null !== requestCurrentTransition()
9006+
? ((fiber = currentEntangledLane),
9007+
0 !== fiber ? fiber : requestTransitionLane())
9008+
: currentUpdatePriority || 32;
90119009
}
90129010
function requestDeferredLane() {
90139011
0 === workInProgressDeferredLane &&
@@ -9352,8 +9350,8 @@ function flushSync(fn) {
93529350
previousPriority = currentUpdatePriority;
93539351
try {
93549352
if (
9355-
((ReactCurrentBatchConfig.transition = null),
9356-
(currentUpdatePriority = 2),
9353+
((currentUpdatePriority = 2),
9354+
(ReactCurrentBatchConfig.transition = null),
93579355
fn)
93589356
)
93599357
return fn();
@@ -9787,11 +9785,11 @@ function commitRoot(
97879785
didIncludeRenderPhaseUpdate,
97889786
spawnedLane
97899787
) {
9790-
var previousUpdateLanePriority = currentUpdatePriority,
9791-
prevTransition = ReactCurrentBatchConfig.transition;
9788+
var prevTransition = ReactCurrentBatchConfig.transition,
9789+
previousUpdateLanePriority = currentUpdatePriority;
97929790
try {
9793-
(ReactCurrentBatchConfig.transition = null),
9794-
(currentUpdatePriority = 2),
9791+
(currentUpdatePriority = 2),
9792+
(ReactCurrentBatchConfig.transition = null),
97959793
commitRootImpl(
97969794
root,
97979795
recoverableErrors,
@@ -9905,14 +9903,13 @@ function flushPassiveEffects() {
99059903
var root = rootWithPendingPassiveEffects,
99069904
remainingLanes = pendingPassiveEffectsRemainingLanes;
99079905
pendingPassiveEffectsRemainingLanes = 0;
9908-
var renderPriority = lanesToEventPriority(pendingPassiveEffectsLanes);
9909-
renderPriority = 32 > renderPriority ? 32 : renderPriority;
9910-
var prevTransition = ReactCurrentBatchConfig.transition,
9906+
var renderPriority = lanesToEventPriority(pendingPassiveEffectsLanes),
9907+
prevTransition = ReactCurrentBatchConfig.transition,
99119908
previousPriority = currentUpdatePriority;
99129909
try {
99139910
return (
9911+
(currentUpdatePriority = 32 > renderPriority ? 32 : renderPriority),
99149912
(ReactCurrentBatchConfig.transition = null),
9915-
(currentUpdatePriority = renderPriority),
99169913
flushPassiveEffectsImpl()
99179914
);
99189915
} finally {
@@ -10657,7 +10654,7 @@ var slice = Array.prototype.slice,
1065710654
return null;
1065810655
},
1065910656
bundleType: 0,
10660-
version: "19.0.0-www-classic-2b02e6e9",
10657+
version: "19.0.0-www-classic-ce2e7147",
1066110658
rendererPackageName: "react-art"
1066210659
};
1066310660
var internals$jscomp$inline_1315 = {
@@ -10688,7 +10685,7 @@ var internals$jscomp$inline_1315 = {
1068810685
scheduleRoot: null,
1068910686
setRefreshHandler: null,
1069010687
getCurrentFiber: null,
10691-
reconcilerVersion: "19.0.0-www-classic-2b02e6e9"
10688+
reconcilerVersion: "19.0.0-www-classic-ce2e7147"
1069210689
};
1069310690
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1069410691
var hook$jscomp$inline_1316 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

0 commit comments

Comments
 (0)