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 commit https://github.com/facebook/react/commit/fec97ecbc4bc2e0e1407160289a8f5fac5241cbc.
This commit is contained in:
acdlite
2023-04-10 18:46:08 +00:00
parent 737b75ed3a
commit b38019bb2f
13 changed files with 40 additions and 31 deletions
@@ -19471,6 +19471,11 @@ function ensureRootIsScheduled(root) {
scheduleImmediateTask(processRootScheduleInMicrotask);
}
}
if (ReactCurrentActQueue$1.isBatchingLegacy && root.tag === LegacyRoot) {
// Special `act` case: Record whenever a legacy update is scheduled.
ReactCurrentActQueue$1.didScheduleLegacyUpdate = true;
}
}
function flushSyncWorkOnAllRoots() {
// This is allowed to be called synchronously, but the caller should check
@@ -20081,10 +20086,8 @@ function scheduleUpdateOnFiber(root, fiber, lane, eventTime) {
executionContext === NoContext &&
(fiber.mode & ConcurrentMode) === NoMode
) {
if (ReactCurrentActQueue.isBatchingLegacy) {
// Treat `act` as if it's inside `batchedUpdates`, even in legacy mode.
ReactCurrentActQueue.didScheduleLegacyUpdate = true;
} else {
if (ReactCurrentActQueue.isBatchingLegacy);
else {
// Flush the synchronous work now, unless we're already working or inside
// a batch. This is intentionally inside scheduleUpdateOnFiber instead of
// scheduleCallbackForFiber to preserve the ability to schedule a callback
@@ -23888,7 +23891,7 @@ function createFiberRoot(
return root;
}
var ReactVersion = "18.3.0-next-9a9da7721-20230409";
var ReactVersion = "18.3.0-next-fec97ecbc-20230410";
// Might add PROFILE later.
@@ -8688,7 +8688,7 @@ var devToolsConfig$jscomp$inline_1028 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-next-9a9da7721-20230409",
version: "18.3.0-next-fec97ecbc-20230410",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1220 = {
@@ -8719,7 +8719,7 @@ var internals$jscomp$inline_1220 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-9a9da7721-20230409"
reconcilerVersion: "18.3.0-next-fec97ecbc-20230410"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1221 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -9114,7 +9114,7 @@ var devToolsConfig$jscomp$inline_1070 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-next-9a9da7721-20230409",
version: "18.3.0-next-fec97ecbc-20230410",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1261 = {
@@ -9145,7 +9145,7 @@ var internals$jscomp$inline_1261 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-9a9da7721-20230409"
reconcilerVersion: "18.3.0-next-fec97ecbc-20230410"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1262 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -27,7 +27,7 @@ if (
}
"use strict";
var ReactVersion = "18.3.0-next-9a9da7721-20230409";
var ReactVersion = "18.3.0-next-fec97ecbc-20230410";
// ATTENTION
// When adding new symbols to this file,
@@ -639,4 +639,4 @@ exports.useSyncExternalStore = function (
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-next-9a9da7721-20230409";
exports.version = "18.3.0-next-fec97ecbc-20230410";
@@ -642,7 +642,7 @@ exports.useSyncExternalStore = function (
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-next-9a9da7721-20230409";
exports.version = "18.3.0-next-fec97ecbc-20230410";
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
if (
@@ -1 +1 @@
9a9da7721e5b73a8af242807e463e2af842c58ee
fec97ecbc4bc2e0e1407160289a8f5fac5241cbc
@@ -22560,6 +22560,11 @@ function ensureRootIsScheduled(root) {
// unblock additional features we have planned.
scheduleTaskForRootDuringMicrotask(root, now$1());
}
if (ReactCurrentActQueue$1.isBatchingLegacy && root.tag === LegacyRoot) {
// Special `act` case: Record whenever a legacy update is scheduled.
ReactCurrentActQueue$1.didScheduleLegacyUpdate = true;
}
}
function flushSyncWorkOnAllRoots() {
// This is allowed to be called synchronously, but the caller should check
@@ -23175,10 +23180,8 @@ function scheduleUpdateOnFiber(root, fiber, lane, eventTime) {
executionContext === NoContext &&
(fiber.mode & ConcurrentMode) === NoMode
) {
if (ReactCurrentActQueue.isBatchingLegacy) {
// Treat `act` as if it's inside `batchedUpdates`, even in legacy mode.
ReactCurrentActQueue.didScheduleLegacyUpdate = true;
} else {
if (ReactCurrentActQueue.isBatchingLegacy);
else {
// Flush the synchronous work now, unless we're already working or inside
// a batch. This is intentionally inside scheduleUpdateOnFiber instead of
// scheduleCallbackForFiber to preserve the ability to schedule a callback
@@ -27184,7 +27187,7 @@ function createFiberRoot(
return root;
}
var ReactVersion = "18.3.0-next-9a9da7721-20230409";
var ReactVersion = "18.3.0-next-fec97ecbc-20230410";
function createPortal$1(
children,
@@ -9555,7 +9555,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1052 = {
findFiberByHostInstance: getInstanceFromNode,
bundleType: 0,
version: "18.3.0-next-9a9da7721-20230409",
version: "18.3.0-next-fec97ecbc-20230410",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForViewTag: function () {
@@ -9597,7 +9597,7 @@ var internals$jscomp$inline_1297 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-9a9da7721-20230409"
reconcilerVersion: "18.3.0-next-fec97ecbc-20230410"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1298 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -10264,7 +10264,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1130 = {
findFiberByHostInstance: getInstanceFromNode,
bundleType: 0,
version: "18.3.0-next-9a9da7721-20230409",
version: "18.3.0-next-fec97ecbc-20230410",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForViewTag: function () {
@@ -10319,7 +10319,7 @@ var roots = new Map(),
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-9a9da7721-20230409"
reconcilerVersion: "18.3.0-next-fec97ecbc-20230410"
});
exports.createPortal = function (children, containerTag) {
return createPortal$1(
@@ -23081,6 +23081,11 @@ function ensureRootIsScheduled(root) {
// unblock additional features we have planned.
scheduleTaskForRootDuringMicrotask(root, now$1());
}
if (ReactCurrentActQueue$1.isBatchingLegacy && root.tag === LegacyRoot) {
// Special `act` case: Record whenever a legacy update is scheduled.
ReactCurrentActQueue$1.didScheduleLegacyUpdate = true;
}
}
function flushSyncWorkOnAllRoots() {
// This is allowed to be called synchronously, but the caller should check
@@ -23696,10 +23701,8 @@ function scheduleUpdateOnFiber(root, fiber, lane, eventTime) {
executionContext === NoContext &&
(fiber.mode & ConcurrentMode) === NoMode
) {
if (ReactCurrentActQueue.isBatchingLegacy) {
// Treat `act` as if it's inside `batchedUpdates`, even in legacy mode.
ReactCurrentActQueue.didScheduleLegacyUpdate = true;
} else {
if (ReactCurrentActQueue.isBatchingLegacy);
else {
// Flush the synchronous work now, unless we're already working or inside
// a batch. This is intentionally inside scheduleUpdateOnFiber instead of
// scheduleCallbackForFiber to preserve the ability to schedule a callback
@@ -27705,7 +27708,7 @@ function createFiberRoot(
return root;
}
var ReactVersion = "18.3.0-next-9a9da7721-20230409";
var ReactVersion = "18.3.0-next-fec97ecbc-20230410";
function createPortal$1(
children,
@@ -9815,7 +9815,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1107 = {
findFiberByHostInstance: getInstanceFromTag,
bundleType: 0,
version: "18.3.0-next-9a9da7721-20230409",
version: "18.3.0-next-fec97ecbc-20230410",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForViewTag: function () {
@@ -9857,7 +9857,7 @@ var internals$jscomp$inline_1359 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-9a9da7721-20230409"
reconcilerVersion: "18.3.0-next-fec97ecbc-20230410"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1360 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -10524,7 +10524,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1185 = {
findFiberByHostInstance: getInstanceFromTag,
bundleType: 0,
version: "18.3.0-next-9a9da7721-20230409",
version: "18.3.0-next-fec97ecbc-20230410",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForViewTag: function () {
@@ -10579,7 +10579,7 @@ var roots = new Map(),
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-9a9da7721-20230409"
reconcilerVersion: "18.3.0-next-fec97ecbc-20230410"
});
exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = {
computeComponentStackForErrorReporting: function (reactTag) {