Add feature flag to use microtasks in the React Native Fabric renderer (#27364)
## Summary This is part of an effort to align the event loop in React Native with its behavior on the Web. In this case, we're going to test enabling microtasks in React Native (Fabric) and we need React to schedule work using microtasks if available there. This just adds a feature flag to configure that behavior at runtime. ## How did you test this change? * Reviewed the generated code, which looks ok. * Did a manual sync of this PR to Meta's internal infra and tested it with my changes to enable microtasks in RN/Hermes.
Rubén Norte committed
Oct 2, 2023 at 17:12 UTC
54baa7997c7b0bbd456460ead6e051655ea43790
10 files changed
+24
-1
packages/react-native-renderer/src/ReactFiberConfigFabric.js
+9
-1
@@ -47,6 +47,8 @@ const {
47
unstable_getCurrentEventPriority: fabricGetCurrentEventPriority,
48
} = nativeFabricUIManager;
49
50
+import {useMicrotasksForSchedulingInFabric} from 'shared/ReactFeatureFlags';
51
+
52
const {get: getViewConfigForType} = ReactNativeViewConfigRegistry;
53
54
// Counter for uniquely identifying views.
@@ -119,7 +121,6 @@ export * from 'react-reconciler/src/ReactFiberConfigWithNoMutation';
121
export * from 'react-reconciler/src/ReactFiberConfigWithNoHydration';
122
export * from 'react-reconciler/src/ReactFiberConfigWithNoScopes';
123
export * from 'react-reconciler/src/ReactFiberConfigWithNoTestSelectors';
122
-export * from 'react-reconciler/src/ReactFiberConfigWithNoMicrotasks';
124
export * from 'react-reconciler/src/ReactFiberConfigWithNoResources';
125
export * from 'react-reconciler/src/ReactFiberConfigWithNoSingletons';
126
@@ -470,3 +471,10 @@ export function waitForCommitToBeReady(): null {
471
}
472
473
export const NotPendingTransition: TransitionStatus = null;
474
+
475
+// -------------------
476
+// Microtasks
477
+// -------------------
478
+export const supportsMicrotasks = useMicrotasksForSchedulingInFabric;
479
+export const scheduleMicrotask: any =
480
+ typeof queueMicrotask === 'function' ? queueMicrotask : scheduleTimeout;
packages/shared/ReactFeatureFlags.js
+2
@@ -122,6 +122,8 @@ export const enableAsyncActions = __EXPERIMENTAL__;
122
123
export const alwaysThrottleRetries = true;
124
125
+export const useMicrotasksForSchedulingInFabric = false;
126
+
127
// -----------------------------------------------------------------------------
128
// Chopping Block
129
//
packages/shared/forks/ReactFeatureFlags.native-fb-dynamic.js
+1
@@ -23,6 +23,7 @@ import typeof * as DynamicFlagsType from 'ReactNativeInternalFeatureFlags';
23
export const enableUseRefAccessWarning = __VARIANT__;
24
export const enableDeferRootSchedulingToMicrotask = __VARIANT__;
25
export const alwaysThrottleRetries = __VARIANT__;
26
+export const useMicrotasksForSchedulingInFabric = __VARIANT__;
27
28
// Flow magic to verify the exports of this file match the original version.
29
((((null: any): ExportsType): DynamicFlagsType): ExportsType);
packages/shared/forks/ReactFeatureFlags.native-fb.js
+1
@@ -21,6 +21,7 @@ export const {
21
enableUseRefAccessWarning,
22
enableDeferRootSchedulingToMicrotask,
23
alwaysThrottleRetries,
24
+ useMicrotasksForSchedulingInFabric,
25
} = dynamicFlags;
26
27
// The rest of the flags are static for better dead code elimination.
packages/shared/forks/ReactFeatureFlags.native-oss.js
+2
@@ -77,5 +77,7 @@ export const enableAsyncActions = false;
77
78
export const alwaysThrottleRetries = true;
79
80
+export const useMicrotasksForSchedulingInFabric = false;
81
+
82
// Flow magic to verify the exports of this file match the original version.
83
((((null: any): ExportsType): FeatureFlagsType): ExportsType);
packages/shared/forks/ReactFeatureFlags.test-renderer.js
+2
@@ -77,5 +77,7 @@ export const enableAsyncActions = false;
77
78
export const alwaysThrottleRetries = true;
79
80
+export const useMicrotasksForSchedulingInFabric = false;
81
+
82
// Flow magic to verify the exports of this file match the original version.
83
((((null: any): ExportsType): FeatureFlagsType): ExportsType);
packages/shared/forks/ReactFeatureFlags.test-renderer.native.js
+2
@@ -74,5 +74,7 @@ export const enableAsyncActions = false;
74
75
export const alwaysThrottleRetries = true;
76
77
+export const useMicrotasksForSchedulingInFabric = false;
78
+
79
// Flow magic to verify the exports of this file match the original version.
80
((((null: any): ExportsType): FeatureFlagsType): ExportsType);
packages/shared/forks/ReactFeatureFlags.test-renderer.www.js
+2
@@ -77,5 +77,7 @@ export const enableAsyncActions = false;
77
78
export const alwaysThrottleRetries = true;
79
80
+export const useMicrotasksForSchedulingInFabric = false;
81
+
82
// Flow magic to verify the exports of this file match the original version.
83
((((null: any): ExportsType): FeatureFlagsType): ExportsType);
packages/shared/forks/ReactFeatureFlags.www.js
+2
@@ -108,5 +108,7 @@ export const enableFizzExternalRuntime = true;
108
109
export const forceConcurrentByDefaultForTesting = false;
110
111
+export const useMicrotasksForSchedulingInFabric = false;
112
+
113
// Flow magic to verify the exports of this file match the original version.
114
((((null: any): ExportsType): FeatureFlagsType): ExportsType);
scripts/flow/xplat.js
+1
@@ -11,4 +11,5 @@ declare module 'ReactNativeInternalFeatureFlags' {
11
declare export var enableUseRefAccessWarning: boolean;
12
declare export var enableDeferRootSchedulingToMicrotask: boolean;
13
declare export var alwaysThrottleRetries: boolean;
14
+ declare export var useMicrotasksForSchedulingInFabric: boolean;
15
}