Skip to content

Commit f5a0c7e

Browse files
committed
[RN] Use microtasks in the RN renderer based on a global flag defined by RN (#28472)
## Summary We want to enable the new event loop in React Native (react-native-community/discussions-and-proposals#744) for all users in the new architecture (determined by the use of bridgeless, not by the use of Fabric). In order to leverage that, we need to also set the flag for the React reconciler to use microtasks for scheduling (so we'll execute them at the right time in the new event loop). This migrates from the previous approach using a dynamic flag (to be used at Meta) with the check of a global set by React Native. The reason for doing this is: 1) We still need to determine this dynamically in OSS (based on Bridgeless, not on Fabric). 2) We still need the ability to configure the behavior at Meta, and for internal build system reasons we cannot access the flag that enables microtasks in [`ReactNativeFeatureFlags`](https://github.com/facebook/react-native/blob/6c28c87c4d5d8a9f5be5e02cd7d3eba5b4aaca8c/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js#L121). ## How did you test this change? Manually synchronized the changes to React Native and ran all tests for the new architecture on it. Also tested manually. > [!NOTE] > This change depends on facebook/react-native#43397 which has been merged already DiffTrain build for commit bb0944f.
1 parent 60c4279 commit f5a0c7e

File tree

10 files changed

+32
-30
lines changed

10 files changed

+32
-30
lines changed

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25454,7 +25454,7 @@ if (__DEV__) {
2545425454
return root;
2545525455
}
2545625456

25457-
var ReactVersion = "18.3.0-canary-d46989150-20240312";
25457+
var ReactVersion = "18.3.0-canary-bb0944fe5-20240313";
2545825458

2545925459
// Might add PROFILE later.
2546025460

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-prod.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9175,7 +9175,7 @@ var devToolsConfig$jscomp$inline_1016 = {
91759175
throw Error("TestRenderer does not support findFiberByHostInstance()");
91769176
},
91779177
bundleType: 0,
9178-
version: "18.3.0-canary-d46989150-20240312",
9178+
version: "18.3.0-canary-bb0944fe5-20240313",
91799179
rendererPackageName: "react-test-renderer"
91809180
};
91819181
var internals$jscomp$inline_1194 = {
@@ -9206,7 +9206,7 @@ var internals$jscomp$inline_1194 = {
92069206
scheduleRoot: null,
92079207
setRefreshHandler: null,
92089208
getCurrentFiber: null,
9209-
reconcilerVersion: "18.3.0-canary-d46989150-20240312"
9209+
reconcilerVersion: "18.3.0-canary-bb0944fe5-20240313"
92109210
};
92119211
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
92129212
var hook$jscomp$inline_1195 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-profiling.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9603,7 +9603,7 @@ var devToolsConfig$jscomp$inline_1058 = {
96039603
throw Error("TestRenderer does not support findFiberByHostInstance()");
96049604
},
96059605
bundleType: 0,
9606-
version: "18.3.0-canary-d46989150-20240312",
9606+
version: "18.3.0-canary-bb0944fe5-20240313",
96079607
rendererPackageName: "react-test-renderer"
96089608
};
96099609
var internals$jscomp$inline_1235 = {
@@ -9634,7 +9634,7 @@ var internals$jscomp$inline_1235 = {
96349634
scheduleRoot: null,
96359635
setRefreshHandler: null,
96369636
getCurrentFiber: null,
9637-
reconcilerVersion: "18.3.0-canary-d46989150-20240312"
9637+
reconcilerVersion: "18.3.0-canary-bb0944fe5-20240313"
96389638
};
96399639
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
96409640
var hook$jscomp$inline_1236 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if (__DEV__) {
2626
}
2727
var dynamicFlags = require("ReactNativeInternalFeatureFlags");
2828

29-
var ReactVersion = "18.3.0-canary-d46989150-20240312";
29+
var ReactVersion = "18.3.0-canary-bb0944fe5-20240313";
3030

3131
// ATTENTION
3232
// When adding new symbols to this file,

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-prod.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,4 +628,4 @@ exports.useSyncExternalStore = function (
628628
exports.useTransition = function () {
629629
return ReactCurrentDispatcher.current.useTransition();
630630
};
631-
exports.version = "18.3.0-canary-d46989150-20240312";
631+
exports.version = "18.3.0-canary-bb0944fe5-20240313";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-profiling.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ exports.useSyncExternalStore = function (
624624
exports.useTransition = function () {
625625
return ReactCurrentDispatcher.current.useTransition();
626626
};
627-
exports.version = "18.3.0-canary-d46989150-20240312";
627+
exports.version = "18.3.0-canary-bb0944fe5-20240313";
628628
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
629629
"function" ===
630630
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
d46989150e9225f2bf299dbca2270596d0829a58
1+
bb0944fe5bdd619be918621a9a1647204d6e7ce1

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<80123652bb9b7be7f517855aca5ff3f1>>
10+
* @generated SignedSource<<9378c92e70cea9a594311fbdc67e5fa3>>
1111
*/
1212

1313
"use strict";
@@ -2987,8 +2987,6 @@ to return true:wantsResponderID| |
29872987
enableUseRefAccessWarning = dynamicFlags.enableUseRefAccessWarning,
29882988
passChildrenWhenCloningPersistedNodes =
29892989
dynamicFlags.passChildrenWhenCloningPersistedNodes,
2990-
useMicrotasksForSchedulingInFabric =
2991-
dynamicFlags.useMicrotasksForSchedulingInFabric,
29922990
useModernStrictMode = dynamicFlags.useModernStrictMode; // The rest of the flags are static for better dead code elimination.
29932991
var enableSchedulingProfiler = true;
29942992
var enableProfilerTimer = true;
@@ -5029,7 +5027,9 @@ to return true:wantsResponderID| |
50295027
// Microtasks
50305028
// -------------------
50315029

5032-
var supportsMicrotasks = useMicrotasksForSchedulingInFabric;
5030+
var supportsMicrotasks =
5031+
typeof RN$enableMicrotasksInReact !== "undefined" &&
5032+
!!RN$enableMicrotasksInReact;
50335033
var scheduleMicrotask =
50345034
typeof queueMicrotask === "function" ? queueMicrotask : scheduleTimeout;
50355035

@@ -29801,7 +29801,7 @@ to return true:wantsResponderID| |
2980129801
return root;
2980229802
}
2980329803

29804-
var ReactVersion = "18.3.0-canary-04bb7356";
29804+
var ReactVersion = "18.3.0-canary-61d1189b";
2980529805

2980629806
function createPortal$1(
2980729807
children,

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-prod.fb.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<79ffaa0355a9d9b89df41eabe7496793>>
10+
* @generated SignedSource<<15dc76ff98842d803f8a59fa78e23283>>
1111
*/
1212

1313
"use strict";
@@ -1278,8 +1278,6 @@ var alwaysThrottleRetries = dynamicFlags.alwaysThrottleRetries,
12781278
enableUseRefAccessWarning = dynamicFlags.enableUseRefAccessWarning,
12791279
passChildrenWhenCloningPersistedNodes =
12801280
dynamicFlags.passChildrenWhenCloningPersistedNodes,
1281-
useMicrotasksForSchedulingInFabric =
1282-
dynamicFlags.useMicrotasksForSchedulingInFabric,
12831281
scheduleCallback$3 = Scheduler.unstable_scheduleCallback,
12841282
cancelCallback$1 = Scheduler.unstable_cancelCallback,
12851283
shouldYield = Scheduler.unstable_shouldYield,
@@ -1601,8 +1599,11 @@ function cloneHiddenInstance(instance) {
16011599
canonical: instance.canonical
16021600
};
16031601
}
1604-
var scheduleMicrotask =
1605-
"function" === typeof queueMicrotask ? queueMicrotask : scheduleTimeout;
1602+
var supportsMicrotasks =
1603+
"undefined" !== typeof RN$enableMicrotasksInReact &&
1604+
!!RN$enableMicrotasksInReact,
1605+
scheduleMicrotask =
1606+
"function" === typeof queueMicrotask ? queueMicrotask : scheduleTimeout;
16061607
function getInstanceFromNode(node) {
16071608
return null != node.canonical && null != node.canonical.internalInstanceHandle
16081609
? node.canonical.internalInstanceHandle
@@ -2329,7 +2330,7 @@ function scheduleTaskForRootDuringMicrotask(root, currentTime) {
23292330
return currentTime;
23302331
}
23312332
function scheduleImmediateTask(cb) {
2332-
useMicrotasksForSchedulingInFabric
2333+
supportsMicrotasks
23332334
? scheduleMicrotask(function () {
23342335
0 !== (executionContext & 6)
23352336
? scheduleCallback$3(ImmediatePriority, cb)
@@ -10625,7 +10626,7 @@ var roots = new Map(),
1062510626
devToolsConfig$jscomp$inline_1103 = {
1062610627
findFiberByHostInstance: getInstanceFromNode,
1062710628
bundleType: 0,
10628-
version: "18.3.0-canary-119507e5",
10629+
version: "18.3.0-canary-1aaf050f",
1062910630
rendererPackageName: "react-native-renderer",
1063010631
rendererConfig: {
1063110632
getInspectorDataForInstance: getInspectorDataForInstance,
@@ -10668,7 +10669,7 @@ var internals$jscomp$inline_1330 = {
1066810669
scheduleRoot: null,
1066910670
setRefreshHandler: null,
1067010671
getCurrentFiber: null,
10671-
reconcilerVersion: "18.3.0-canary-119507e5"
10672+
reconcilerVersion: "18.3.0-canary-1aaf050f"
1067210673
};
1067310674
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1067410675
var hook$jscomp$inline_1331 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-profiling.fb.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<3a1a367017d4c9c4d53a27776b68c3f9>>
10+
* @generated SignedSource<<d2ad8cf505447dec09fe24623849b875>>
1111
*/
1212

1313
"use strict";
@@ -1282,8 +1282,6 @@ var alwaysThrottleRetries = dynamicFlags.alwaysThrottleRetries,
12821282
enableUseRefAccessWarning = dynamicFlags.enableUseRefAccessWarning,
12831283
passChildrenWhenCloningPersistedNodes =
12841284
dynamicFlags.passChildrenWhenCloningPersistedNodes,
1285-
useMicrotasksForSchedulingInFabric =
1286-
dynamicFlags.useMicrotasksForSchedulingInFabric,
12871285
scheduleCallback$3 = Scheduler.unstable_scheduleCallback,
12881286
cancelCallback$1 = Scheduler.unstable_cancelCallback,
12891287
shouldYield = Scheduler.unstable_shouldYield,
@@ -1723,8 +1721,11 @@ function cloneHiddenInstance(instance) {
17231721
canonical: instance.canonical
17241722
};
17251723
}
1726-
var scheduleMicrotask =
1727-
"function" === typeof queueMicrotask ? queueMicrotask : scheduleTimeout;
1724+
var supportsMicrotasks =
1725+
"undefined" !== typeof RN$enableMicrotasksInReact &&
1726+
!!RN$enableMicrotasksInReact,
1727+
scheduleMicrotask =
1728+
"function" === typeof queueMicrotask ? queueMicrotask : scheduleTimeout;
17281729
function getInstanceFromNode(node) {
17291730
return null != node.canonical && null != node.canonical.internalInstanceHandle
17301731
? node.canonical.internalInstanceHandle
@@ -2453,7 +2454,7 @@ function scheduleTaskForRootDuringMicrotask(root, currentTime) {
24532454
return currentTime;
24542455
}
24552456
function scheduleImmediateTask(cb) {
2456-
useMicrotasksForSchedulingInFabric
2457+
supportsMicrotasks
24572458
? scheduleMicrotask(function () {
24582459
0 !== (executionContext & 6)
24592460
? scheduleCallback$3(ImmediatePriority, cb)
@@ -11331,7 +11332,7 @@ var roots = new Map(),
1133111332
devToolsConfig$jscomp$inline_1184 = {
1133211333
findFiberByHostInstance: getInstanceFromNode,
1133311334
bundleType: 0,
11334-
version: "18.3.0-canary-ca9ab9fa",
11335+
version: "18.3.0-canary-7d52778b",
1133511336
rendererPackageName: "react-native-renderer",
1133611337
rendererConfig: {
1133711338
getInspectorDataForInstance: getInspectorDataForInstance,
@@ -11387,7 +11388,7 @@ var roots = new Map(),
1138711388
scheduleRoot: null,
1138811389
setRefreshHandler: null,
1138911390
getCurrentFiber: null,
11390-
reconcilerVersion: "18.3.0-canary-ca9ab9fa"
11391+
reconcilerVersion: "18.3.0-canary-7d52778b"
1139111392
});
1139211393
exports.createPortal = function (children, containerTag) {
1139311394
return createPortal$1(

0 commit comments

Comments
 (0)