Skip to content

Commit 3b81f25

Browse files
rubennorteAndyPengc12
authored andcommitted
[RN] Use microtasks in the RN renderer based on a global flag defined by RN (facebook#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
1 parent 117b305 commit 3b81f25

13 files changed

+11
-15
lines changed

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ module.exports = {
427427
files: ['packages/react-native-renderer/**/*.js'],
428428
globals: {
429429
nativeFabricUIManager: 'readonly',
430+
RN$enableMicrotasksInReact: 'readonly',
430431
},
431432
},
432433
{

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ const {
4747
unstable_getCurrentEventPriority: fabricGetCurrentEventPriority,
4848
} = nativeFabricUIManager;
4949

50-
import {
51-
useMicrotasksForSchedulingInFabric,
52-
passChildrenWhenCloningPersistedNodes,
53-
} from 'shared/ReactFeatureFlags';
50+
import {passChildrenWhenCloningPersistedNodes} from 'shared/ReactFeatureFlags';
5451

5552
const {get: getViewConfigForType} = ReactNativeViewConfigRegistry;
5653

@@ -507,6 +504,10 @@ export const NotPendingTransition: TransitionStatus = null;
507504
// -------------------
508505
// Microtasks
509506
// -------------------
510-
export const supportsMicrotasks = useMicrotasksForSchedulingInFabric;
507+
508+
export const supportsMicrotasks: boolean =
509+
typeof RN$enableMicrotasksInReact !== 'undefined' &&
510+
!!RN$enableMicrotasksInReact;
511+
511512
export const scheduleMicrotask: any =
512513
typeof queueMicrotask === 'function' ? queueMicrotask : scheduleTimeout;

packages/shared/ReactFeatureFlags.js

-2
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ export const enableFizzExternalRuntime = true;
115115

116116
export const alwaysThrottleRetries = true;
117117

118-
export const useMicrotasksForSchedulingInFabric = false;
119-
120118
export const passChildrenWhenCloningPersistedNodes = false;
121119

122120
export const enableUseDeferredValueInitialArg = __EXPERIMENTAL__;

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

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export const enableRenderableContext = __VARIANT__;
3030
export const enableUnifiedSyncLane = __VARIANT__;
3131
export const enableUseRefAccessWarning = __VARIANT__;
3232
export const passChildrenWhenCloningPersistedNodes = __VARIANT__;
33-
export const useMicrotasksForSchedulingInFabric = __VARIANT__;
3433
export const useModernStrictMode = __VARIANT__;
3534

3635
// Flow magic to verify the exports of this file match the original version.

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

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export const {
2828
enableUnifiedSyncLane,
2929
enableUseRefAccessWarning,
3030
passChildrenWhenCloningPersistedNodes,
31-
useMicrotasksForSchedulingInFabric,
3231
useModernStrictMode,
3332
} = dynamicFlags;
3433

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

-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ export const enableAsyncActions = false;
8080

8181
export const alwaysThrottleRetries = false;
8282

83-
export const useMicrotasksForSchedulingInFabric = false;
8483
export const passChildrenWhenCloningPersistedNodes = false;
8584
export const enableUseDeferredValueInitialArg = __EXPERIMENTAL__;
8685
export const disableClientCache = true;

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

-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ export const enableAsyncActions = true;
7878

7979
export const alwaysThrottleRetries = true;
8080

81-
export const useMicrotasksForSchedulingInFabric = false;
8281
export const passChildrenWhenCloningPersistedNodes = false;
8382
export const enableUseDeferredValueInitialArg = __EXPERIMENTAL__;
8483
export const disableClientCache = true;

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

-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ export const enableAsyncActions = true;
7878

7979
export const alwaysThrottleRetries = true;
8080

81-
export const useMicrotasksForSchedulingInFabric = false;
8281
export const passChildrenWhenCloningPersistedNodes = false;
8382
export const enableUseDeferredValueInitialArg = __EXPERIMENTAL__;
8483
export const disableClientCache = true;

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

-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ export const enableAsyncActions = true;
7979

8080
export const alwaysThrottleRetries = true;
8181

82-
export const useMicrotasksForSchedulingInFabric = false;
8382
export const passChildrenWhenCloningPersistedNodes = false;
8483
export const enableUseDeferredValueInitialArg = true;
8584
export const disableClientCache = true;

packages/shared/forks/ReactFeatureFlags.www.js

-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ export const enableFizzExternalRuntime = true;
106106

107107
export const forceConcurrentByDefaultForTesting = false;
108108

109-
export const useMicrotasksForSchedulingInFabric = false;
110109
export const passChildrenWhenCloningPersistedNodes = false;
111110

112111
export const enableAsyncDebugInfo = false;

scripts/flow/react-native-host-hooks.js

+2
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'
167167
declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInitializeCore' {
168168
}
169169

170+
declare const RN$enableMicrotasksInReact: boolean;
171+
170172
// This is needed for a short term solution.
171173
// See https://github.com/facebook/react/pull/15490 for more info
172174
declare var nativeFabricUIManager: {

scripts/flow/xplat.js

-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@ declare module 'ReactNativeInternalFeatureFlags' {
1818
declare export var enableUnifiedSyncLane: boolean;
1919
declare export var enableUseRefAccessWarning: boolean;
2020
declare export var passChildrenWhenCloningPersistedNodes: boolean;
21-
declare export var useMicrotasksForSchedulingInFabric: boolean;
2221
declare export var useModernStrictMode: boolean;
2322
}

scripts/rollup/validate/eslintrc.rn.js

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ module.exports = {
4242
// Fabric. See https://github.com/facebook/react/pull/15490
4343
// for more information
4444
nativeFabricUIManager: 'readonly',
45+
// RN flag to enable microtasks
46+
RN$enableMicrotasksInReact: 'readonly',
4547
// Trusted Types
4648
trustedTypes: 'readonly',
4749
// RN supports this

0 commit comments

Comments
 (0)