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 [fec97ecbc4bc2e0e1407160289a8f5fac5241cbc](facebook/react@fec97ec)
  • Loading branch information
jerrydev0927 committed Apr 10, 2023
1 parent 920655a commit 0bafd81
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 50 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9a9da7721e5b73a8af242807e463e2af842c58ee
fec97ecbc4bc2e0e1407160289a8f5fac5241cbc
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (
}
"use strict";

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

// ATTENTION
// When adding new symbols to this file,
Expand Down
13 changes: 8 additions & 5 deletions compiled/facebook-www/ReactART-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function _assertThisInitialized(self) {
return self;
}

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

var LegacyRoot = 0;
var ConcurrentRoot = 1;
Expand Down Expand Up @@ -23173,6 +23173,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 @@ -23980,10 +23985,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
13 changes: 8 additions & 5 deletions compiled/facebook-www/ReactART-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function _assertThisInitialized(self) {
return self;
}

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

var LegacyRoot = 0;
var ConcurrentRoot = 1;
Expand Down Expand Up @@ -22838,6 +22838,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 @@ -23645,10 +23650,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
4 changes: 2 additions & 2 deletions compiled/facebook-www/ReactART-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -9737,7 +9737,7 @@ var slice = Array.prototype.slice,
return null;
},
bundleType: 0,
version: "18.3.0-www-modern-3b22d407",
version: "18.3.0-www-modern-77b45d24",
rendererPackageName: "react-art"
};
var internals$jscomp$inline_1324 = {
Expand Down Expand Up @@ -9768,7 +9768,7 @@ var internals$jscomp$inline_1324 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-www-modern-3b22d407"
reconcilerVersion: "18.3.0-www-modern-77b45d24"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1325 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
13 changes: 8 additions & 5 deletions compiled/facebook-www/ReactDOM-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -28134,6 +28134,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 @@ -28959,10 +28964,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 @@ -33348,7 +33351,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-www-classic-1bf554dd";
var ReactVersion = "18.3.0-www-classic-27be8f4e";

function createPortal$1(
children,
Expand Down
13 changes: 8 additions & 5 deletions compiled/facebook-www/ReactDOM-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -27975,6 +27975,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 @@ -28800,10 +28805,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 @@ -33184,7 +33187,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-www-modern-3b22d407";
var ReactVersion = "18.3.0-www-modern-77b45d24";

function createPortal$1(
children,
Expand Down
13 changes: 8 additions & 5 deletions compiled/facebook-www/ReactDOMTesting-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -31325,6 +31325,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 @@ -32150,10 +32155,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 @@ -36539,7 +36542,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-www-classic-49934517";
var ReactVersion = "18.3.0-www-classic-ca64d104";

function createPortal$1(
children,
Expand Down
13 changes: 8 additions & 5 deletions compiled/facebook-www/ReactDOMTesting-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -28594,6 +28594,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 @@ -29419,10 +29424,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 @@ -33803,7 +33806,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-www-modern-845598d4";
var ReactVersion = "18.3.0-www-modern-835f126b";

function createPortal$1(
children,
Expand Down
6 changes: 3 additions & 3 deletions compiled/facebook-www/ReactDOMTesting-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -14773,7 +14773,7 @@ Internals.Events = [
var devToolsConfig$jscomp$inline_1769 = {
findFiberByHostInstance: getClosestInstanceFromNode,
bundleType: 0,
version: "18.3.0-www-classic-4f49fe42",
version: "18.3.0-www-classic-b7529c47",
rendererPackageName: "react-dom"
};
var internals$jscomp$inline_2211 = {
Expand Down Expand Up @@ -14803,7 +14803,7 @@ var internals$jscomp$inline_2211 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-www-classic-4f49fe42"
reconcilerVersion: "18.3.0-www-classic-b7529c47"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_2212 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down Expand Up @@ -16805,4 +16805,4 @@ exports.unstable_renderSubtreeIntoContainer = function (
);
};
exports.unstable_runWithPriority = runWithPriority;
exports.version = "18.3.0-www-classic-4f49fe42";
exports.version = "18.3.0-www-classic-b7529c47";
6 changes: 3 additions & 3 deletions compiled/facebook-www/ReactDOMTesting-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -15966,7 +15966,7 @@ Internals.Events = [
var devToolsConfig$jscomp$inline_1799 = {
findFiberByHostInstance: getClosestInstanceFromNode,
bundleType: 0,
version: "18.3.0-www-modern-bfaf8fe7",
version: "18.3.0-www-modern-0ed50ada",
rendererPackageName: "react-dom"
};
var internals$jscomp$inline_2178 = {
Expand Down Expand Up @@ -15997,7 +15997,7 @@ var internals$jscomp$inline_2178 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-www-modern-bfaf8fe7"
reconcilerVersion: "18.3.0-www-modern-0ed50ada"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_2179 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down Expand Up @@ -16317,4 +16317,4 @@ exports.unstable_createEventHandle = function (type, options) {
return eventHandle;
};
exports.unstable_runWithPriority = runWithPriority;
exports.version = "18.3.0-www-modern-bfaf8fe7";
exports.version = "18.3.0-www-modern-0ed50ada";
13 changes: 8 additions & 5 deletions compiled/facebook-www/ReactTestRenderer-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -20063,6 +20063,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 @@ -20673,10 +20678,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 @@ -24498,7 +24501,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-www-classic-4acb9da4";
var ReactVersion = "18.3.0-www-classic-ce15662b";

// Might add PROFILE later.

Expand Down
13 changes: 8 additions & 5 deletions compiled/facebook-www/ReactTestRenderer-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -20063,6 +20063,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 @@ -20673,10 +20678,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 @@ -24498,7 +24501,7 @@ function createFiberRoot(
return root;
}

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

// Might add PROFILE later.

Expand Down

0 comments on commit 0bafd81

Please sign in to comment.