Skip to content

Commit bb0944f

Browse files
authored
[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
1 parent d469891 commit bb0944f

13 files changed

Lines changed: 11 additions & 15 deletions

.eslintrc.js

Lines changed: 1 addition & 0 deletions
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

Lines changed: 6 additions & 5 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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;

0 commit comments

Comments
 (0)