Skip to content

Commit

Permalink
act: Move didScheduleLegacyUpdate to ensureRootIsScheduled (#26552)
Browse files Browse the repository at this point in the history
`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 fec97ec.
  • Loading branch information
acdlite committed Apr 10, 2023
1 parent 737b75e commit b38019b
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9a9da7721e5b73a8af242807e463e2af842c58ee
fec97ecbc4bc2e0e1407160289a8f5fac5241cbc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b38019b

Please sign in to comment.