From c608edabbae5158fefb80b747fc86ff25829c0cf Mon Sep 17 00:00:00 2001 From: acdlite Date: Mon, 10 Apr 2023 18:46:20 +0000 Subject: [PATCH] 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 [fec97ecbc4bc2e0e1407160289a8f5fac5241cbc](https://github.com/facebook/react/commit/fec97ecbc4bc2e0e1407160289a8f5fac5241cbc) --- compiled/facebook-www/REVISION | 2 +- compiled/facebook-www/React-dev.modern.js | 2 +- compiled/facebook-www/ReactART-dev.classic.js | 13 ++++++++----- compiled/facebook-www/ReactART-dev.modern.js | 13 ++++++++----- compiled/facebook-www/ReactART-prod.modern.js | 4 ++-- compiled/facebook-www/ReactDOM-dev.classic.js | 13 ++++++++----- compiled/facebook-www/ReactDOM-dev.modern.js | 13 ++++++++----- .../facebook-www/ReactDOMTesting-dev.classic.js | 13 ++++++++----- compiled/facebook-www/ReactDOMTesting-dev.modern.js | 13 ++++++++----- .../facebook-www/ReactDOMTesting-prod.classic.js | 6 +++--- .../facebook-www/ReactDOMTesting-prod.modern.js | 6 +++--- .../facebook-www/ReactTestRenderer-dev.classic.js | 13 ++++++++----- .../facebook-www/ReactTestRenderer-dev.modern.js | 13 ++++++++----- 13 files changed, 74 insertions(+), 50 deletions(-) diff --git a/compiled/facebook-www/REVISION b/compiled/facebook-www/REVISION index 3adc486c22..2c7137467b 100644 --- a/compiled/facebook-www/REVISION +++ b/compiled/facebook-www/REVISION @@ -1 +1 @@ -9a9da7721e5b73a8af242807e463e2af842c58ee +fec97ecbc4bc2e0e1407160289a8f5fac5241cbc diff --git a/compiled/facebook-www/React-dev.modern.js b/compiled/facebook-www/React-dev.modern.js index d9367dd1ec..fda9ac59f7 100644 --- a/compiled/facebook-www/React-dev.modern.js +++ b/compiled/facebook-www/React-dev.modern.js @@ -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, diff --git a/compiled/facebook-www/ReactART-dev.classic.js b/compiled/facebook-www/ReactART-dev.classic.js index dac2fcccde..a773b0a750 100644 --- a/compiled/facebook-www/ReactART-dev.classic.js +++ b/compiled/facebook-www/ReactART-dev.classic.js @@ -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; @@ -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 @@ -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 diff --git a/compiled/facebook-www/ReactART-dev.modern.js b/compiled/facebook-www/ReactART-dev.modern.js index 21dd38df7d..4e1c010d1e 100644 --- a/compiled/facebook-www/ReactART-dev.modern.js +++ b/compiled/facebook-www/ReactART-dev.modern.js @@ -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; @@ -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 @@ -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 diff --git a/compiled/facebook-www/ReactART-prod.modern.js b/compiled/facebook-www/ReactART-prod.modern.js index 86065d1e80..68ce4a6507 100644 --- a/compiled/facebook-www/ReactART-prod.modern.js +++ b/compiled/facebook-www/ReactART-prod.modern.js @@ -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 = { @@ -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__; diff --git a/compiled/facebook-www/ReactDOM-dev.classic.js b/compiled/facebook-www/ReactDOM-dev.classic.js index c6c24500d2..3fe6e4a0c4 100644 --- a/compiled/facebook-www/ReactDOM-dev.classic.js +++ b/compiled/facebook-www/ReactDOM-dev.classic.js @@ -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 @@ -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 @@ -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, diff --git a/compiled/facebook-www/ReactDOM-dev.modern.js b/compiled/facebook-www/ReactDOM-dev.modern.js index da3f037ba2..45abe365ce 100644 --- a/compiled/facebook-www/ReactDOM-dev.modern.js +++ b/compiled/facebook-www/ReactDOM-dev.modern.js @@ -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 @@ -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 @@ -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, diff --git a/compiled/facebook-www/ReactDOMTesting-dev.classic.js b/compiled/facebook-www/ReactDOMTesting-dev.classic.js index 153739d085..a9623c1fa7 100644 --- a/compiled/facebook-www/ReactDOMTesting-dev.classic.js +++ b/compiled/facebook-www/ReactDOMTesting-dev.classic.js @@ -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 @@ -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 @@ -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, diff --git a/compiled/facebook-www/ReactDOMTesting-dev.modern.js b/compiled/facebook-www/ReactDOMTesting-dev.modern.js index a4149ea6ab..a04198d979 100644 --- a/compiled/facebook-www/ReactDOMTesting-dev.modern.js +++ b/compiled/facebook-www/ReactDOMTesting-dev.modern.js @@ -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 @@ -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 @@ -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, diff --git a/compiled/facebook-www/ReactDOMTesting-prod.classic.js b/compiled/facebook-www/ReactDOMTesting-prod.classic.js index 339d193531..d996784bce 100644 --- a/compiled/facebook-www/ReactDOMTesting-prod.classic.js +++ b/compiled/facebook-www/ReactDOMTesting-prod.classic.js @@ -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 = { @@ -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__; @@ -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"; diff --git a/compiled/facebook-www/ReactDOMTesting-prod.modern.js b/compiled/facebook-www/ReactDOMTesting-prod.modern.js index 86d1726d9a..41943a910d 100644 --- a/compiled/facebook-www/ReactDOMTesting-prod.modern.js +++ b/compiled/facebook-www/ReactDOMTesting-prod.modern.js @@ -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 = { @@ -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__; @@ -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"; diff --git a/compiled/facebook-www/ReactTestRenderer-dev.classic.js b/compiled/facebook-www/ReactTestRenderer-dev.classic.js index 76ef5ff5db..0efc75e3a9 100644 --- a/compiled/facebook-www/ReactTestRenderer-dev.classic.js +++ b/compiled/facebook-www/ReactTestRenderer-dev.classic.js @@ -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 @@ -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 @@ -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. diff --git a/compiled/facebook-www/ReactTestRenderer-dev.modern.js b/compiled/facebook-www/ReactTestRenderer-dev.modern.js index 405b792916..ccd7ecaeee 100644 --- a/compiled/facebook-www/ReactTestRenderer-dev.modern.js +++ b/compiled/facebook-www/ReactTestRenderer-dev.modern.js @@ -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 @@ -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 @@ -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.