From b38019bb2ff90ea3da1493903f17c89dd2919f23 Mon Sep 17 00:00:00 2001 From: acdlite Date: Mon, 10 Apr 2023 18:46:08 +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 commit https://github.com/facebook/react/commit/fec97ecbc4bc2e0e1407160289a8f5fac5241cbc. --- .../cjs/ReactTestRenderer-dev.js | 13 ++++++++----- .../cjs/ReactTestRenderer-prod.js | 4 ++-- .../cjs/ReactTestRenderer-profiling.js | 4 ++-- .../js/RKJSModules/vendor/react/cjs/React-dev.js | 2 +- .../js/RKJSModules/vendor/react/cjs/React-prod.js | 2 +- .../RKJSModules/vendor/react/cjs/React-profiling.js | 2 +- .../react-native-github/Libraries/Renderer/REVISION | 2 +- .../Renderer/implementations/ReactFabric-dev.fb.js | 13 ++++++++----- .../Renderer/implementations/ReactFabric-prod.fb.js | 4 ++-- .../implementations/ReactFabric-profiling.fb.js | 4 ++-- .../implementations/ReactNativeRenderer-dev.fb.js | 13 ++++++++----- .../implementations/ReactNativeRenderer-prod.fb.js | 4 ++-- .../ReactNativeRenderer-profiling.fb.js | 4 ++-- 13 files changed, 40 insertions(+), 31 deletions(-) diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-dev.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-dev.js index 0c145677cf..a9bcbcba90 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-dev.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-dev.js @@ -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. diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-prod.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-prod.js index 18b30731bd..ce6b7d423e 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-prod.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-prod.js @@ -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__; diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-profiling.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-profiling.js index e88ab0905c..d72127f9ad 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-profiling.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-profiling.js @@ -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__; diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-dev.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-dev.js index eb609cc774..ad22ae28b6 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-dev.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-dev.js @@ -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, diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-prod.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-prod.js index 0a45709488..d72a935086 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-prod.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-prod.js @@ -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"; diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-profiling.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-profiling.js index 72b5051af3..5e75265cf9 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-profiling.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-profiling.js @@ -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 ( diff --git a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/REVISION b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/REVISION index 3adc486c22..2c7137467b 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/REVISION +++ b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/REVISION @@ -1 +1 @@ -9a9da7721e5b73a8af242807e463e2af842c58ee +fec97ecbc4bc2e0e1407160289a8f5fac5241cbc diff --git a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js index 3bac533d9d..febcd91d6e 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js +++ b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js @@ -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, diff --git a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-prod.fb.js b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-prod.fb.js index 2df9cbc06a..5d7a00d1f0 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-prod.fb.js +++ b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-prod.fb.js @@ -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__; diff --git a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-profiling.fb.js b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-profiling.fb.js index 566eabb618..8d2eb9274b 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-profiling.fb.js +++ b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-profiling.fb.js @@ -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( diff --git a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-dev.fb.js b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-dev.fb.js index 4b03d1e0c9..24ab0b31f5 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-dev.fb.js +++ b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-dev.fb.js @@ -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, diff --git a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-prod.fb.js b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-prod.fb.js index bcdc376e63..dbb88153ff 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-prod.fb.js +++ b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-prod.fb.js @@ -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__; diff --git a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.fb.js b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.fb.js index ec3c6da9df..1190563da8 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.fb.js +++ b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.fb.js @@ -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) {