From 11c49d60ccc88ccd7ec0431436a0d0df2999c176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Thu, 12 Dec 2024 05:41:01 -0800 Subject: [PATCH] Make feature flags module and overrides read-only (#48229) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48229 Changelog: [internal] The type definitions for these objects (the exported value by the `ReactNativeFeatureFlags` module, and the input value for `ReactNativeFeatureFlags.override()` method) were writable objects, which is incorrect and causes other problems down the line. This just makes them read-only. Reviewed By: yungsters Differential Revision: D67109719 fbshipit-source-id: 8d56e05042587a53cdd05e51b4207ef27ace2d91 --- .../js/ReactNativeFeatureFlags.js-template.js | 8 ++++---- .../private/featureflags/ReactNativeFeatureFlags.js | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/react-native/scripts/featureflags/templates/js/ReactNativeFeatureFlags.js-template.js b/packages/react-native/scripts/featureflags/templates/js/ReactNativeFeatureFlags.js-template.js index b542fd1bbc7..5bf488ba9fb 100644 --- a/packages/react-native/scripts/featureflags/templates/js/ReactNativeFeatureFlags.js-template.js +++ b/packages/react-native/scripts/featureflags/templates/js/ReactNativeFeatureFlags.js-template.js @@ -34,18 +34,18 @@ import { setOverrides, } from './ReactNativeFeatureFlagsBase'; -export type ReactNativeFeatureFlagsJsOnly = { +export type ReactNativeFeatureFlagsJsOnly = $ReadOnly<{ ${Object.entries(definitions.jsOnly) .map( ([flagName, flagConfig]) => ` ${flagName}: Getter<${typeof flagConfig.defaultValue}>,`, ) .join('\n')} -}; +}>; export type ReactNativeFeatureFlagsJsOnlyOverrides = OverridesFor; -export type ReactNativeFeatureFlags = { +export type ReactNativeFeatureFlags = $ReadOnly<{ ...ReactNativeFeatureFlagsJsOnly, ${Object.entries(definitions.common) .map( @@ -53,7 +53,7 @@ ${Object.entries(definitions.common) ` ${flagName}: Getter<${typeof flagConfig.defaultValue}>,`, ) .join('\n')} -} +}>; ${Object.entries(definitions.jsOnly) .map( diff --git a/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js b/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js index 62b82fc6f45..bd181dd552b 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<<52cce0be8ae96e530267bf0dbbcfbd2d>> + * @generated SignedSource<<0c6bca5d443beff11d70a5cba470607f>> * @flow strict */ @@ -26,7 +26,7 @@ import { setOverrides, } from './ReactNativeFeatureFlagsBase'; -export type ReactNativeFeatureFlagsJsOnly = { +export type ReactNativeFeatureFlagsJsOnly = $ReadOnly<{ jsOnlyTestFlag: Getter, animatedShouldDebounceQueueFlush: Getter, animatedShouldUseSingleOp: Getter, @@ -44,11 +44,11 @@ export type ReactNativeFeatureFlagsJsOnly = { shouldUseSetNativePropsInFabric: Getter, useInsertionEffectsForAnimations: Getter, useRefsForTextInputState: Getter, -}; +}>; export type ReactNativeFeatureFlagsJsOnlyOverrides = OverridesFor; -export type ReactNativeFeatureFlags = { +export type ReactNativeFeatureFlags = $ReadOnly<{ ...ReactNativeFeatureFlagsJsOnly, commonTestFlag: Getter, commonTestFlagWithoutNativeImplementation: Getter, @@ -98,7 +98,7 @@ export type ReactNativeFeatureFlags = { useRuntimeShadowNodeReferenceUpdate: Getter, useTurboModuleInterop: Getter, useTurboModules: Getter, -} +}>; /** * JS-only flag for testing. Do NOT modify.