Skip to content

Commit c608eda

Browse files
committed
act: Move didScheduleLegacyUpdate to ensureRootIsScheduled (#26552)
`act` uses the `didScheduleLegacyUpdate` field to simulate the behavior of batching in React <17 and below. It's a quirk leftover from a previous implementation, not intentionally designed. This sets `didScheduleLegacyUpdate` every time a legacy root receives an update as opposed to only when the `executionContext` is empty. There's no real reason to do it this way over some other way except that it's how it used to work before #26512 and we should try our best to maintain the existing behavior, quirks and all, since existing tests may have come to accidentally rely on it. This should fix some (though not all) of the internal Meta tests that started failing after #26512 landed. Will add a regression test before merging. DiffTrain build for [fec97ec](fec97ec)
1 parent 75825ff commit c608eda

13 files changed

+74
-50
lines changed

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9a9da7721e5b73a8af242807e463e2af842c58ee
1+
fec97ecbc4bc2e0e1407160289a8f5fac5241cbc

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if (
2727
}
2828
"use strict";
2929

30-
var ReactVersion = "18.3.0-www-modern-bfaf8fe7";
30+
var ReactVersion = "18.3.0-www-modern-0ed50ada";
3131

3232
// ATTENTION
3333
// When adding new symbols to this file,

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function _assertThisInitialized(self) {
6969
return self;
7070
}
7171

72-
var ReactVersion = "18.3.0-www-classic-4f49fe42";
72+
var ReactVersion = "18.3.0-www-classic-b7529c47";
7373

7474
var LegacyRoot = 0;
7575
var ConcurrentRoot = 1;
@@ -23173,6 +23173,11 @@ function ensureRootIsScheduled(root) {
2317323173
// unblock additional features we have planned.
2317423174
scheduleTaskForRootDuringMicrotask(root, now$1());
2317523175
}
23176+
23177+
if (ReactCurrentActQueue$1.isBatchingLegacy && root.tag === LegacyRoot) {
23178+
// Special `act` case: Record whenever a legacy update is scheduled.
23179+
ReactCurrentActQueue$1.didScheduleLegacyUpdate = true;
23180+
}
2317623181
}
2317723182
function flushSyncWorkOnAllRoots() {
2317823183
// This is allowed to be called synchronously, but the caller should check
@@ -23980,10 +23985,8 @@ function scheduleUpdateOnFiber(root, fiber, lane, eventTime) {
2398023985
executionContext === NoContext &&
2398123986
(fiber.mode & ConcurrentMode) === NoMode
2398223987
) {
23983-
if (ReactCurrentActQueue.isBatchingLegacy) {
23984-
// Treat `act` as if it's inside `batchedUpdates`, even in legacy mode.
23985-
ReactCurrentActQueue.didScheduleLegacyUpdate = true;
23986-
} else {
23988+
if (ReactCurrentActQueue.isBatchingLegacy);
23989+
else {
2398723990
// Flush the synchronous work now, unless we're already working or inside
2398823991
// a batch. This is intentionally inside scheduleUpdateOnFiber instead of
2398923992
// scheduleCallbackForFiber to preserve the ability to schedule a callback

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function _assertThisInitialized(self) {
6969
return self;
7070
}
7171

72-
var ReactVersion = "18.3.0-www-modern-c67d4626";
72+
var ReactVersion = "18.3.0-www-modern-71e9d049";
7373

7474
var LegacyRoot = 0;
7575
var ConcurrentRoot = 1;
@@ -22838,6 +22838,11 @@ function ensureRootIsScheduled(root) {
2283822838
// unblock additional features we have planned.
2283922839
scheduleTaskForRootDuringMicrotask(root, now$1());
2284022840
}
22841+
22842+
if (ReactCurrentActQueue$1.isBatchingLegacy && root.tag === LegacyRoot) {
22843+
// Special `act` case: Record whenever a legacy update is scheduled.
22844+
ReactCurrentActQueue$1.didScheduleLegacyUpdate = true;
22845+
}
2284122846
}
2284222847
function flushSyncWorkOnAllRoots() {
2284322848
// This is allowed to be called synchronously, but the caller should check
@@ -23645,10 +23650,8 @@ function scheduleUpdateOnFiber(root, fiber, lane, eventTime) {
2364523650
executionContext === NoContext &&
2364623651
(fiber.mode & ConcurrentMode) === NoMode
2364723652
) {
23648-
if (ReactCurrentActQueue.isBatchingLegacy) {
23649-
// Treat `act` as if it's inside `batchedUpdates`, even in legacy mode.
23650-
ReactCurrentActQueue.didScheduleLegacyUpdate = true;
23651-
} else {
23653+
if (ReactCurrentActQueue.isBatchingLegacy);
23654+
else {
2365223655
// Flush the synchronous work now, unless we're already working or inside
2365323656
// a batch. This is intentionally inside scheduleUpdateOnFiber instead of
2365423657
// scheduleCallbackForFiber to preserve the ability to schedule a callback

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9737,7 +9737,7 @@ var slice = Array.prototype.slice,
97379737
return null;
97389738
},
97399739
bundleType: 0,
9740-
version: "18.3.0-www-modern-3b22d407",
9740+
version: "18.3.0-www-modern-77b45d24",
97419741
rendererPackageName: "react-art"
97429742
};
97439743
var internals$jscomp$inline_1324 = {
@@ -9768,7 +9768,7 @@ var internals$jscomp$inline_1324 = {
97689768
scheduleRoot: null,
97699769
setRefreshHandler: null,
97709770
getCurrentFiber: null,
9771-
reconcilerVersion: "18.3.0-www-modern-3b22d407"
9771+
reconcilerVersion: "18.3.0-www-modern-77b45d24"
97729772
};
97739773
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
97749774
var hook$jscomp$inline_1325 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28134,6 +28134,11 @@ function ensureRootIsScheduled(root) {
2813428134
// unblock additional features we have planned.
2813528135
scheduleTaskForRootDuringMicrotask(root, now$1());
2813628136
}
28137+
28138+
if (ReactCurrentActQueue$1.isBatchingLegacy && root.tag === LegacyRoot) {
28139+
// Special `act` case: Record whenever a legacy update is scheduled.
28140+
ReactCurrentActQueue$1.didScheduleLegacyUpdate = true;
28141+
}
2813728142
}
2813828143
function flushSyncWorkOnAllRoots() {
2813928144
// This is allowed to be called synchronously, but the caller should check
@@ -28959,10 +28964,8 @@ function scheduleUpdateOnFiber(root, fiber, lane, eventTime) {
2895928964
executionContext === NoContext &&
2896028965
(fiber.mode & ConcurrentMode) === NoMode
2896128966
) {
28962-
if (ReactCurrentActQueue.isBatchingLegacy) {
28963-
// Treat `act` as if it's inside `batchedUpdates`, even in legacy mode.
28964-
ReactCurrentActQueue.didScheduleLegacyUpdate = true;
28965-
} else {
28967+
if (ReactCurrentActQueue.isBatchingLegacy);
28968+
else {
2896628969
// Flush the synchronous work now, unless we're already working or inside
2896728970
// a batch. This is intentionally inside scheduleUpdateOnFiber instead of
2896828971
// scheduleCallbackForFiber to preserve the ability to schedule a callback
@@ -33348,7 +33351,7 @@ function createFiberRoot(
3334833351
return root;
3334933352
}
3335033353

33351-
var ReactVersion = "18.3.0-www-classic-1bf554dd";
33354+
var ReactVersion = "18.3.0-www-classic-27be8f4e";
3335233355

3335333356
function createPortal$1(
3335433357
children,

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27975,6 +27975,11 @@ function ensureRootIsScheduled(root) {
2797527975
// unblock additional features we have planned.
2797627976
scheduleTaskForRootDuringMicrotask(root, now$1());
2797727977
}
27978+
27979+
if (ReactCurrentActQueue$1.isBatchingLegacy && root.tag === LegacyRoot) {
27980+
// Special `act` case: Record whenever a legacy update is scheduled.
27981+
ReactCurrentActQueue$1.didScheduleLegacyUpdate = true;
27982+
}
2797827983
}
2797927984
function flushSyncWorkOnAllRoots() {
2798027985
// This is allowed to be called synchronously, but the caller should check
@@ -28800,10 +28805,8 @@ function scheduleUpdateOnFiber(root, fiber, lane, eventTime) {
2880028805
executionContext === NoContext &&
2880128806
(fiber.mode & ConcurrentMode) === NoMode
2880228807
) {
28803-
if (ReactCurrentActQueue.isBatchingLegacy) {
28804-
// Treat `act` as if it's inside `batchedUpdates`, even in legacy mode.
28805-
ReactCurrentActQueue.didScheduleLegacyUpdate = true;
28806-
} else {
28808+
if (ReactCurrentActQueue.isBatchingLegacy);
28809+
else {
2880728810
// Flush the synchronous work now, unless we're already working or inside
2880828811
// a batch. This is intentionally inside scheduleUpdateOnFiber instead of
2880928812
// scheduleCallbackForFiber to preserve the ability to schedule a callback
@@ -33184,7 +33187,7 @@ function createFiberRoot(
3318433187
return root;
3318533188
}
3318633189

33187-
var ReactVersion = "18.3.0-www-modern-3b22d407";
33190+
var ReactVersion = "18.3.0-www-modern-77b45d24";
3318833191

3318933192
function createPortal$1(
3319033193
children,

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31325,6 +31325,11 @@ function ensureRootIsScheduled(root) {
3132531325
// unblock additional features we have planned.
3132631326
scheduleTaskForRootDuringMicrotask(root, now$1());
3132731327
}
31328+
31329+
if (ReactCurrentActQueue$1.isBatchingLegacy && root.tag === LegacyRoot) {
31330+
// Special `act` case: Record whenever a legacy update is scheduled.
31331+
ReactCurrentActQueue$1.didScheduleLegacyUpdate = true;
31332+
}
3132831333
}
3132931334
function flushSyncWorkOnAllRoots() {
3133031335
// This is allowed to be called synchronously, but the caller should check
@@ -32150,10 +32155,8 @@ function scheduleUpdateOnFiber(root, fiber, lane, eventTime) {
3215032155
executionContext === NoContext &&
3215132156
(fiber.mode & ConcurrentMode) === NoMode
3215232157
) {
32153-
if (ReactCurrentActQueue.isBatchingLegacy) {
32154-
// Treat `act` as if it's inside `batchedUpdates`, even in legacy mode.
32155-
ReactCurrentActQueue.didScheduleLegacyUpdate = true;
32156-
} else {
32158+
if (ReactCurrentActQueue.isBatchingLegacy);
32159+
else {
3215732160
// Flush the synchronous work now, unless we're already working or inside
3215832161
// a batch. This is intentionally inside scheduleUpdateOnFiber instead of
3215932162
// scheduleCallbackForFiber to preserve the ability to schedule a callback
@@ -36539,7 +36542,7 @@ function createFiberRoot(
3653936542
return root;
3654036543
}
3654136544

36542-
var ReactVersion = "18.3.0-www-classic-49934517";
36545+
var ReactVersion = "18.3.0-www-classic-ca64d104";
3654336546

3654436547
function createPortal$1(
3654536548
children,

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28594,6 +28594,11 @@ function ensureRootIsScheduled(root) {
2859428594
// unblock additional features we have planned.
2859528595
scheduleTaskForRootDuringMicrotask(root, now$1());
2859628596
}
28597+
28598+
if (ReactCurrentActQueue$1.isBatchingLegacy && root.tag === LegacyRoot) {
28599+
// Special `act` case: Record whenever a legacy update is scheduled.
28600+
ReactCurrentActQueue$1.didScheduleLegacyUpdate = true;
28601+
}
2859728602
}
2859828603
function flushSyncWorkOnAllRoots() {
2859928604
// This is allowed to be called synchronously, but the caller should check
@@ -29419,10 +29424,8 @@ function scheduleUpdateOnFiber(root, fiber, lane, eventTime) {
2941929424
executionContext === NoContext &&
2942029425
(fiber.mode & ConcurrentMode) === NoMode
2942129426
) {
29422-
if (ReactCurrentActQueue.isBatchingLegacy) {
29423-
// Treat `act` as if it's inside `batchedUpdates`, even in legacy mode.
29424-
ReactCurrentActQueue.didScheduleLegacyUpdate = true;
29425-
} else {
29427+
if (ReactCurrentActQueue.isBatchingLegacy);
29428+
else {
2942629429
// Flush the synchronous work now, unless we're already working or inside
2942729430
// a batch. This is intentionally inside scheduleUpdateOnFiber instead of
2942829431
// scheduleCallbackForFiber to preserve the ability to schedule a callback
@@ -33803,7 +33806,7 @@ function createFiberRoot(
3380333806
return root;
3380433807
}
3380533808

33806-
var ReactVersion = "18.3.0-www-modern-845598d4";
33809+
var ReactVersion = "18.3.0-www-modern-835f126b";
3380733810

3380833811
function createPortal$1(
3380933812
children,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14773,7 +14773,7 @@ Internals.Events = [
1477314773
var devToolsConfig$jscomp$inline_1769 = {
1477414774
findFiberByHostInstance: getClosestInstanceFromNode,
1477514775
bundleType: 0,
14776-
version: "18.3.0-www-classic-4f49fe42",
14776+
version: "18.3.0-www-classic-b7529c47",
1477714777
rendererPackageName: "react-dom"
1477814778
};
1477914779
var internals$jscomp$inline_2211 = {
@@ -14803,7 +14803,7 @@ var internals$jscomp$inline_2211 = {
1480314803
scheduleRoot: null,
1480414804
setRefreshHandler: null,
1480514805
getCurrentFiber: null,
14806-
reconcilerVersion: "18.3.0-www-classic-4f49fe42"
14806+
reconcilerVersion: "18.3.0-www-classic-b7529c47"
1480714807
};
1480814808
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1480914809
var hook$jscomp$inline_2212 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -16805,4 +16805,4 @@ exports.unstable_renderSubtreeIntoContainer = function (
1680516805
);
1680616806
};
1680716807
exports.unstable_runWithPriority = runWithPriority;
16808-
exports.version = "18.3.0-www-classic-4f49fe42";
16808+
exports.version = "18.3.0-www-classic-b7529c47";

compiled/facebook-www/ReactDOMTesting-prod.modern.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15966,7 +15966,7 @@ Internals.Events = [
1596615966
var devToolsConfig$jscomp$inline_1799 = {
1596715967
findFiberByHostInstance: getClosestInstanceFromNode,
1596815968
bundleType: 0,
15969-
version: "18.3.0-www-modern-bfaf8fe7",
15969+
version: "18.3.0-www-modern-0ed50ada",
1597015970
rendererPackageName: "react-dom"
1597115971
};
1597215972
var internals$jscomp$inline_2178 = {
@@ -15997,7 +15997,7 @@ var internals$jscomp$inline_2178 = {
1599715997
scheduleRoot: null,
1599815998
setRefreshHandler: null,
1599915999
getCurrentFiber: null,
16000-
reconcilerVersion: "18.3.0-www-modern-bfaf8fe7"
16000+
reconcilerVersion: "18.3.0-www-modern-0ed50ada"
1600116001
};
1600216002
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1600316003
var hook$jscomp$inline_2179 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -16317,4 +16317,4 @@ exports.unstable_createEventHandle = function (type, options) {
1631716317
return eventHandle;
1631816318
};
1631916319
exports.unstable_runWithPriority = runWithPriority;
16320-
exports.version = "18.3.0-www-modern-bfaf8fe7";
16320+
exports.version = "18.3.0-www-modern-0ed50ada";

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20063,6 +20063,11 @@ function ensureRootIsScheduled(root) {
2006320063
scheduleImmediateTask(processRootScheduleInMicrotask);
2006420064
}
2006520065
}
20066+
20067+
if (ReactCurrentActQueue$1.isBatchingLegacy && root.tag === LegacyRoot) {
20068+
// Special `act` case: Record whenever a legacy update is scheduled.
20069+
ReactCurrentActQueue$1.didScheduleLegacyUpdate = true;
20070+
}
2006620071
}
2006720072
function flushSyncWorkOnAllRoots() {
2006820073
// This is allowed to be called synchronously, but the caller should check
@@ -20673,10 +20678,8 @@ function scheduleUpdateOnFiber(root, fiber, lane, eventTime) {
2067320678
executionContext === NoContext &&
2067420679
(fiber.mode & ConcurrentMode) === NoMode
2067520680
) {
20676-
if (ReactCurrentActQueue.isBatchingLegacy) {
20677-
// Treat `act` as if it's inside `batchedUpdates`, even in legacy mode.
20678-
ReactCurrentActQueue.didScheduleLegacyUpdate = true;
20679-
} else {
20681+
if (ReactCurrentActQueue.isBatchingLegacy);
20682+
else {
2068020683
// Flush the synchronous work now, unless we're already working or inside
2068120684
// a batch. This is intentionally inside scheduleUpdateOnFiber instead of
2068220685
// scheduleCallbackForFiber to preserve the ability to schedule a callback
@@ -24498,7 +24501,7 @@ function createFiberRoot(
2449824501
return root;
2449924502
}
2450024503

24501-
var ReactVersion = "18.3.0-www-classic-4acb9da4";
24504+
var ReactVersion = "18.3.0-www-classic-ce15662b";
2450224505

2450324506
// Might add PROFILE later.
2450424507

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20063,6 +20063,11 @@ function ensureRootIsScheduled(root) {
2006320063
scheduleImmediateTask(processRootScheduleInMicrotask);
2006420064
}
2006520065
}
20066+
20067+
if (ReactCurrentActQueue$1.isBatchingLegacy && root.tag === LegacyRoot) {
20068+
// Special `act` case: Record whenever a legacy update is scheduled.
20069+
ReactCurrentActQueue$1.didScheduleLegacyUpdate = true;
20070+
}
2006620071
}
2006720072
function flushSyncWorkOnAllRoots() {
2006820073
// This is allowed to be called synchronously, but the caller should check
@@ -20673,10 +20678,8 @@ function scheduleUpdateOnFiber(root, fiber, lane, eventTime) {
2067320678
executionContext === NoContext &&
2067420679
(fiber.mode & ConcurrentMode) === NoMode
2067520680
) {
20676-
if (ReactCurrentActQueue.isBatchingLegacy) {
20677-
// Treat `act` as if it's inside `batchedUpdates`, even in legacy mode.
20678-
ReactCurrentActQueue.didScheduleLegacyUpdate = true;
20679-
} else {
20681+
if (ReactCurrentActQueue.isBatchingLegacy);
20682+
else {
2068020683
// Flush the synchronous work now, unless we're already working or inside
2068120684
// a batch. This is intentionally inside scheduleUpdateOnFiber instead of
2068220685
// scheduleCallbackForFiber to preserve the ability to schedule a callback
@@ -24498,7 +24501,7 @@ function createFiberRoot(
2449824501
return root;
2449924502
}
2450024503

24501-
var ReactVersion = "18.3.0-www-modern-bfaf8fe7";
24504+
var ReactVersion = "18.3.0-www-modern-0ed50ada";
2450224505

2450324506
// Might add PROFILE later.
2450424507

0 commit comments

Comments
 (0)