Skip to content

Commit 15e547f

Browse files
rubennorteAndyPengc12
authored andcommitted
Add feature flag to use microtasks in the React Native Fabric renderer (facebook#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.
1 parent 8295268 commit 15e547f

10 files changed

+24
-1
lines changed

packages/react-native-renderer/src/ReactFiberConfigFabric.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ const {
4747
unstable_getCurrentEventPriority: fabricGetCurrentEventPriority,
4848
} = nativeFabricUIManager;
4949

50+
import {useMicrotasksForSchedulingInFabric} from 'shared/ReactFeatureFlags';
51+
5052
const {get: getViewConfigForType} = ReactNativeViewConfigRegistry;
5153

5254
// Counter for uniquely identifying views.
@@ -119,7 +121,6 @@ export * from 'react-reconciler/src/ReactFiberConfigWithNoMutation';
119121
export * from 'react-reconciler/src/ReactFiberConfigWithNoHydration';
120122
export * from 'react-reconciler/src/ReactFiberConfigWithNoScopes';
121123
export * from 'react-reconciler/src/ReactFiberConfigWithNoTestSelectors';
122-
export * from 'react-reconciler/src/ReactFiberConfigWithNoMicrotasks';
123124
export * from 'react-reconciler/src/ReactFiberConfigWithNoResources';
124125
export * from 'react-reconciler/src/ReactFiberConfigWithNoSingletons';
125126

@@ -470,3 +471,10 @@ export function waitForCommitToBeReady(): null {
470471
}
471472

472473
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ export const enableAsyncActions = __EXPERIMENTAL__;
122122

123123
export const alwaysThrottleRetries = true;
124124

125+
export const useMicrotasksForSchedulingInFabric = false;
126+
125127
// -----------------------------------------------------------------------------
126128
// Chopping Block
127129
//

packages/shared/forks/ReactFeatureFlags.native-fb-dynamic.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import typeof * as DynamicFlagsType from 'ReactNativeInternalFeatureFlags';
2323
export const enableUseRefAccessWarning = __VARIANT__;
2424
export const enableDeferRootSchedulingToMicrotask = __VARIANT__;
2525
export const alwaysThrottleRetries = __VARIANT__;
26+
export const useMicrotasksForSchedulingInFabric = __VARIANT__;
2627

2728
// Flow magic to verify the exports of this file match the original version.
2829
((((null: any): ExportsType): DynamicFlagsType): ExportsType);

packages/shared/forks/ReactFeatureFlags.native-fb.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const {
2121
enableUseRefAccessWarning,
2222
enableDeferRootSchedulingToMicrotask,
2323
alwaysThrottleRetries,
24+
useMicrotasksForSchedulingInFabric,
2425
} = dynamicFlags;
2526

2627
// The rest of the flags are static for better dead code elimination.

packages/shared/forks/ReactFeatureFlags.native-oss.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,7 @@ export const enableAsyncActions = false;
7777

7878
export const alwaysThrottleRetries = true;
7979

80+
export const useMicrotasksForSchedulingInFabric = false;
81+
8082
// Flow magic to verify the exports of this file match the original version.
8183
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

packages/shared/forks/ReactFeatureFlags.test-renderer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,7 @@ export const enableAsyncActions = false;
7777

7878
export const alwaysThrottleRetries = true;
7979

80+
export const useMicrotasksForSchedulingInFabric = false;
81+
8082
// Flow magic to verify the exports of this file match the original version.
8183
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

packages/shared/forks/ReactFeatureFlags.test-renderer.native.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,7 @@ export const enableAsyncActions = false;
7474

7575
export const alwaysThrottleRetries = true;
7676

77+
export const useMicrotasksForSchedulingInFabric = false;
78+
7779
// Flow magic to verify the exports of this file match the original version.
7880
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

packages/shared/forks/ReactFeatureFlags.test-renderer.www.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,7 @@ export const enableAsyncActions = false;
7777

7878
export const alwaysThrottleRetries = true;
7979

80+
export const useMicrotasksForSchedulingInFabric = false;
81+
8082
// Flow magic to verify the exports of this file match the original version.
8183
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

packages/shared/forks/ReactFeatureFlags.www.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,7 @@ export const enableFizzExternalRuntime = true;
108108

109109
export const forceConcurrentByDefaultForTesting = false;
110110

111+
export const useMicrotasksForSchedulingInFabric = false;
112+
111113
// Flow magic to verify the exports of this file match the original version.
112114
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

scripts/flow/xplat.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ declare module 'ReactNativeInternalFeatureFlags' {
1111
declare export var enableUseRefAccessWarning: boolean;
1212
declare export var enableDeferRootSchedulingToMicrotask: boolean;
1313
declare export var alwaysThrottleRetries: boolean;
14+
declare export var useMicrotasksForSchedulingInFabric: boolean;
1415
}

0 commit comments

Comments
 (0)