From 82cc465645d7a765707f703a14b4af809a018df8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Thu, 30 Jan 2025 07:20:52 -0800 Subject: [PATCH] Clean up disableEventLoopOnBridgeless feature flag (#49065) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/49065 Changelog: [internal] Cleaning up the flag because it's no longer necessary. Reviewed By: sammy-SC Differential Revision: D68892995 fbshipit-source-id: 4e0290bfb11181dc388e6590af1b82581588b9ee --- .../Libraries/Core/setUpTimers.js | 115 +++++++----------- .../NativeReactNativeFeatureFlags.cpp | 9 +- .../NativeReactNativeFeatureFlags.h | 4 +- .../ReactNativeFeatureFlags.config.js | 10 -- .../featureflags/ReactNativeFeatureFlags.js | 7 +- .../specs/NativeReactNativeFeatureFlags.js | 3 +- 6 files changed, 51 insertions(+), 97 deletions(-) diff --git a/packages/react-native/Libraries/Core/setUpTimers.js b/packages/react-native/Libraries/Core/setUpTimers.js index 8dd5188f9f2..db8baa3e058 100644 --- a/packages/react-native/Libraries/Core/setUpTimers.js +++ b/packages/react-native/Libraries/Core/setUpTimers.js @@ -10,9 +10,6 @@ 'use strict'; -const ReactNativeFeatureFlags = require('../../src/private/featureflags/ReactNativeFeatureFlags'); -const NativeReactNativeFeatureFlags = - require('../../src/private/featureflags/specs/NativeReactNativeFeatureFlags').default; const {polyfillGlobal} = require('../Utilities/PolyfillFunctions'); if (__DEV__) { @@ -21,19 +18,46 @@ if (__DEV__) { } } -const isEventLoopEnabled = (() => { - if (NativeReactNativeFeatureFlags == null) { - return false; - } - - return ( - ReactNativeFeatureFlags.enableBridgelessArchitecture() && - !ReactNativeFeatureFlags.disableEventLoopOnBridgeless() - ); -})(); - // In bridgeless mode, timers are host functions installed from cpp. -if (global.RN$Bridgeless !== true) { +if (global.RN$Bridgeless === true) { + // This is the flag that tells React to use `queueMicrotask` to batch state + // updates, instead of using the scheduler to schedule a regular task. + // We use a global variable because we don't currently have any other + // mechanism to pass feature flags from RN to React in OSS. + global.RN$enableMicrotasksInReact = true; + + polyfillGlobal( + 'queueMicrotask', + () => + require('../../src/private/webapis/microtasks/specs/NativeMicrotasks') + .default.queueMicrotask, + ); + + // We shim the immediate APIs via `queueMicrotask` to maintain the backward + // compatibility. + polyfillGlobal( + 'setImmediate', + () => require('./Timers/immediateShim').setImmediate, + ); + polyfillGlobal( + 'clearImmediate', + () => require('./Timers/immediateShim').clearImmediate, + ); + + polyfillGlobal( + 'requestIdleCallback', + () => + require('../../src/private/webapis/idlecallbacks/specs/NativeIdleCallbacks') + .default.requestIdleCallback, + ); + + polyfillGlobal( + 'cancelIdleCallback', + () => + require('../../src/private/webapis/idlecallbacks/specs/NativeIdleCallbacks') + .default.cancelIdleCallback, + ); +} else { /** * Set up timers. * You can use this module directly, or just require InitializeCore. @@ -59,50 +83,7 @@ if (global.RN$Bridgeless !== true) { defineLazyTimer('cancelAnimationFrame'); defineLazyTimer('requestIdleCallback'); defineLazyTimer('cancelIdleCallback'); -} else if (isEventLoopEnabled) { - polyfillGlobal( - 'requestIdleCallback', - () => - require('../../src/private/webapis/idlecallbacks/specs/NativeIdleCallbacks') - .default.requestIdleCallback, - ); - polyfillGlobal( - 'cancelIdleCallback', - () => - require('../../src/private/webapis/idlecallbacks/specs/NativeIdleCallbacks') - .default.cancelIdleCallback, - ); -} - -// We need to check if the native module is available before accessing the -// feature flag, because otherwise the API would throw an error in the legacy -// architecture in OSS, where the native module isn't available. -if (isEventLoopEnabled) { - // This is the flag that tells React to use `queueMicrotask` to batch state - // updates, instead of using the scheduler to schedule a regular task. - // We use a global variable because we don't currently have any other - // mechanism to pass feature flags from RN to React in OSS. - global.RN$enableMicrotasksInReact = true; - - polyfillGlobal( - 'queueMicrotask', - () => - require('../../src/private/webapis/microtasks/specs/NativeMicrotasks') - .default.queueMicrotask, - ); - - // We shim the immediate APIs via `queueMicrotask` to maintain the backward - // compatibility. - polyfillGlobal( - 'setImmediate', - () => require('./Timers/immediateShim').setImmediate, - ); - polyfillGlobal( - 'clearImmediate', - () => require('./Timers/immediateShim').clearImmediate, - ); -} else { // Polyfill it with promise (regardless it's polyfilled or native) otherwise. polyfillGlobal( 'queueMicrotask', @@ -112,14 +93,12 @@ if (isEventLoopEnabled) { // When promise was polyfilled hence is queued to the RN microtask queue, // we polyfill the immediate APIs as aliases to the ReactNativeMicrotask APIs. // Note that in bridgeless mode, immediate APIs are installed from cpp. - if (global.RN$Bridgeless !== true) { - polyfillGlobal( - 'setImmediate', - () => require('./Timers/JSTimers').default.queueReactNativeMicrotask, - ); - polyfillGlobal( - 'clearImmediate', - () => require('./Timers/JSTimers').default.clearReactNativeMicrotask, - ); - } + polyfillGlobal( + 'setImmediate', + () => require('./Timers/JSTimers').default.queueReactNativeMicrotask, + ); + polyfillGlobal( + 'clearImmediate', + () => require('./Timers/JSTimers').default.clearReactNativeMicrotask, + ); } diff --git a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp index 4bbbba6d751..ec190b4a154 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<6b314d87b09e65d8c70a0d3f4caf953a>> + * @generated SignedSource<<0d5df5cac07efb95bfd5f0984f960a0b>> */ /** @@ -49,13 +49,6 @@ bool NativeReactNativeFeatureFlags::commonTestFlagWithoutNativeImplementation( return false; } -bool NativeReactNativeFeatureFlags::disableEventLoopOnBridgeless( - jsi::Runtime& /*runtime*/) { - // This flag is configured with `skipNativeAPI: true`. - // TODO(T204838867): Implement support for optional methods in C++ TM codegen and remove the method definition altogether. - return false; -} - bool NativeReactNativeFeatureFlags::disableMountItemReorderingAndroid( jsi::Runtime& /*runtime*/) { return ReactNativeFeatureFlags::disableMountItemReorderingAndroid(); diff --git a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h index 7b6eca3462a..e5557dfaa7b 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h +++ b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<3b3ce0cfc8578f517393b89dc76a9aac>> + * @generated SignedSource<<44a75d78e4910acb405e79e9953f563a>> */ /** @@ -39,8 +39,6 @@ class NativeReactNativeFeatureFlags bool commonTestFlagWithoutNativeImplementation(jsi::Runtime& runtime); - bool disableEventLoopOnBridgeless(jsi::Runtime& runtime); - bool disableMountItemReorderingAndroid(jsi::Runtime& runtime); bool enableAccumulatedUpdatesInRawPropsAndroid(jsi::Runtime& runtime); diff --git a/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js b/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js index e28c892c95a..b9bda4a20a5 100644 --- a/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js +++ b/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js @@ -57,16 +57,6 @@ const testDefinitions: FeatureFlagDefinitions = { const definitions: FeatureFlagDefinitions = { common: { ...testDefinitions.common, - disableEventLoopOnBridgeless: { - defaultValue: false, - metadata: { - description: - 'The bridgeless architecture enables the event loop by default. This feature flag allows us to force disabling it in specific instances.', - expectedReleaseValue: true, - purpose: 'release', - }, - skipNativeAPI: true, - }, disableMountItemReorderingAndroid: { defaultValue: false, metadata: { diff --git a/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js b/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js index 96fc19ceb22..2899d14ed52 100644 --- a/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js +++ b/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<> + * @generated SignedSource<<7d66477e7b024c551085f068a6445014>> * @flow strict */ @@ -50,7 +50,6 @@ export type ReactNativeFeatureFlags = $ReadOnly<{ ...ReactNativeFeatureFlagsJsOnly, commonTestFlag: Getter, commonTestFlagWithoutNativeImplementation: Getter, - disableEventLoopOnBridgeless: Getter, disableMountItemReorderingAndroid: Getter, enableAccumulatedUpdatesInRawPropsAndroid: Getter, enableBridgelessArchitecture: Getter, @@ -176,10 +175,6 @@ export const commonTestFlag: Getter = createNativeFlagGetter('commonTes * Common flag for testing (without native implementation). Do NOT modify. */ export const commonTestFlagWithoutNativeImplementation: Getter = createNativeFlagGetter('commonTestFlagWithoutNativeImplementation', false, true); -/** - * The bridgeless architecture enables the event loop by default. This feature flag allows us to force disabling it in specific instances. - */ -export const disableEventLoopOnBridgeless: Getter = createNativeFlagGetter('disableEventLoopOnBridgeless', false, true); /** * Prevent FabricMountingManager from reordering mountitems, which may lead to invalid state on the UI thread */ diff --git a/packages/react-native/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js b/packages/react-native/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js index eb63439b22d..f055ab637b4 100644 --- a/packages/react-native/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +++ b/packages/react-native/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<> + * @generated SignedSource<<73d10e1985377162b75ee60e5bcad8dd>> * @flow strict */ @@ -25,7 +25,6 @@ import * as TurboModuleRegistry from '../../../../Libraries/TurboModule/TurboMod export interface Spec extends TurboModule { +commonTestFlag?: () => boolean; +commonTestFlagWithoutNativeImplementation?: () => boolean; - +disableEventLoopOnBridgeless?: () => boolean; +disableMountItemReorderingAndroid?: () => boolean; +enableAccumulatedUpdatesInRawPropsAndroid?: () => boolean; +enableBridgelessArchitecture?: () => boolean;