Add feature flag for using shadow node state on clone (#50751)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/50751

See title

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D73067007

fbshipit-source-id: 2a67ed33ebd35ffaa3470d75ef6f695471820fa6
This commit is contained in:
Nick Lefever authored and Facebook GitHub Bot committed 2025-04-16 18:58:26 -07:00
1 parent 539f2377a4
commit b962646079
20 files changed
+139 -22

No files matched your search

@@ -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<<745904568803a9ead98bc10210b38938>>
* @generated SignedSource<<794bf258fbb453ea71a39c5459316a24>>
*/
/**
@@ -264,6 +264,12 @@ public object ReactNativeFeatureFlags {
@JvmStatic
public fun useRawPropsJsiValue(): Boolean = accessor.useRawPropsJsiValue()
/**
* Use the state stored on the source shadow node when cloning it instead of reading in the most recent state on the shadow node family.
*/
@JvmStatic
public fun useShadowNodeStateOnClone(): Boolean = accessor.useShadowNodeStateOnClone()
/**
* In Bridgeless mode, should legacy NativeModules use the TurboModule system?
*/
@@ -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<<4f9df3bdf8c353ccbdfeea0f0d378e01>>
* @generated SignedSource<<43260e9f0b5774bdb3d60915bcd28ea3>>
*/
/**
@@ -59,6 +59,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
private var useNativeViewConfigsInBridgelessModeCache: Boolean? = null
private var useOptimizedEventBatchingOnAndroidCache: Boolean? = null
private var useRawPropsJsiValueCache: Boolean? = null
private var useShadowNodeStateOnCloneCache: Boolean? = null
private var useTurboModuleInteropCache: Boolean? = null
private var useTurboModulesCache: Boolean? = null
@@ -413,6 +414,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
return cached
}
override fun useShadowNodeStateOnClone(): Boolean {
var cached = useShadowNodeStateOnCloneCache
if (cached == null) {
cached = ReactNativeFeatureFlagsCxxInterop.useShadowNodeStateOnClone()
useShadowNodeStateOnCloneCache = cached
}
return cached
}
override fun useTurboModuleInterop(): Boolean {
var cached = useTurboModuleInteropCache
if (cached == null) {
@@ -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<<8200512b24c8ddd99e582b24e858f1f8>>
* @generated SignedSource<<1f3845a6aad6babd4404adfb433f4b38>>
*/
/**
@@ -106,6 +106,8 @@ public object ReactNativeFeatureFlagsCxxInterop {
@DoNotStrip @JvmStatic public external fun useRawPropsJsiValue(): Boolean
@DoNotStrip @JvmStatic public external fun useShadowNodeStateOnClone(): Boolean
@DoNotStrip @JvmStatic public external fun useTurboModuleInterop(): Boolean
@DoNotStrip @JvmStatic public external fun useTurboModules(): Boolean
@@ -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<<92ac1a25b3c5eb4e43334e0c65e5255f>>
* @generated SignedSource<<6f24701d1581b744185caaee1ca5fc06>>
*/
/**
@@ -101,6 +101,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
override fun useRawPropsJsiValue(): Boolean = false
override fun useShadowNodeStateOnClone(): Boolean = false
override fun useTurboModuleInterop(): Boolean = false
override fun useTurboModules(): Boolean = false
@@ -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<<c7d8c0c6ff5a50925692cca2de48c537>>
* @generated SignedSource<<8988a69695658c92f013e736dec8f5fc>>
*/
/**
@@ -63,6 +63,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
private var useNativeViewConfigsInBridgelessModeCache: Boolean? = null
private var useOptimizedEventBatchingOnAndroidCache: Boolean? = null
private var useRawPropsJsiValueCache: Boolean? = null
private var useShadowNodeStateOnCloneCache: Boolean? = null
private var useTurboModuleInteropCache: Boolean? = null
private var useTurboModulesCache: Boolean? = null
@@ -456,6 +457,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
return cached
}
override fun useShadowNodeStateOnClone(): Boolean {
var cached = useShadowNodeStateOnCloneCache
if (cached == null) {
cached = currentProvider.useShadowNodeStateOnClone()
accessedFeatureFlags.add("useShadowNodeStateOnClone")
useShadowNodeStateOnCloneCache = cached
}
return cached
}
override fun useTurboModuleInterop(): Boolean {
var cached = useTurboModuleInteropCache
if (cached == null) {
@@ -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<<54e0deb6c78833a3f0394d4ff2ab9562>>
* @generated SignedSource<<646efad3c8769005e893ad63d78b8c6c>>
*/
/**
@@ -101,6 +101,8 @@ public interface ReactNativeFeatureFlagsProvider {
@DoNotStrip public fun useRawPropsJsiValue(): Boolean
@DoNotStrip public fun useShadowNodeStateOnClone(): Boolean
@DoNotStrip public fun useTurboModuleInterop(): Boolean
@DoNotStrip public fun useTurboModules(): Boolean
@@ -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<<d944ced839aa053484befb1496749b9e>>
* @generated SignedSource<<cfbc50cc7a2ce2dbff3447c697d45797>>
*/
/**
@@ -273,6 +273,12 @@ class ReactNativeFeatureFlagsJavaProvider
return method(javaProvider_);
}
bool useShadowNodeStateOnClone() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("useShadowNodeStateOnClone");
return method(javaProvider_);
}
bool useTurboModuleInterop() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("useTurboModuleInterop");
@@ -484,6 +490,11 @@ bool JReactNativeFeatureFlagsCxxInterop::useRawPropsJsiValue(
return ReactNativeFeatureFlags::useRawPropsJsiValue();
}
bool JReactNativeFeatureFlagsCxxInterop::useShadowNodeStateOnClone(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::useShadowNodeStateOnClone();
}
bool JReactNativeFeatureFlagsCxxInterop::useTurboModuleInterop(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::useTurboModuleInterop();
@@ -642,6 +653,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
makeNativeMethod(
"useRawPropsJsiValue",
JReactNativeFeatureFlagsCxxInterop::useRawPropsJsiValue),
makeNativeMethod(
"useShadowNodeStateOnClone",
JReactNativeFeatureFlagsCxxInterop::useShadowNodeStateOnClone),
makeNativeMethod(
"useTurboModuleInterop",
JReactNativeFeatureFlagsCxxInterop::useTurboModuleInterop),
@@ -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<<c122826c2dd42cfb66e96e1af5c7a54a>>
* @generated SignedSource<<58c3ec4bdf7b171ea6203ed100116c50>>
*/
/**
@@ -147,6 +147,9 @@ class JReactNativeFeatureFlagsCxxInterop
static bool useRawPropsJsiValue(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
static bool useShadowNodeStateOnClone(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
static bool useTurboModuleInterop(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
@@ -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<<f98498698a19d59cc4113bf6bbc0b2ea>>
* @generated SignedSource<<55680628f0480fce8c955fbde539ae47>>
*/
/**
@@ -182,6 +182,10 @@ bool ReactNativeFeatureFlags::useRawPropsJsiValue() {
return getAccessor().useRawPropsJsiValue();
}
bool ReactNativeFeatureFlags::useShadowNodeStateOnClone() {
return getAccessor().useShadowNodeStateOnClone();
}
bool ReactNativeFeatureFlags::useTurboModuleInterop() {
return getAccessor().useTurboModuleInterop();
}
@@ -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<<aa1cc3b66b13bf529e06239c018ad515>>
* @generated SignedSource<<136de88435026f3bfb2d785d1a12b707>>
*/
/**
@@ -234,6 +234,11 @@ class ReactNativeFeatureFlags {
*/
RN_EXPORT static bool useRawPropsJsiValue();
/**
* Use the state stored on the source shadow node when cloning it instead of reading in the most recent state on the shadow node family.
*/
RN_EXPORT static bool useShadowNodeStateOnClone();
/**
* In Bridgeless mode, should legacy NativeModules use the TurboModule system?
*/
@@ -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<<ed39775341d5f6a93d8c5974309eb9b4>>
* @generated SignedSource<<6f18b18b4aa1ef98f94bf4f595a59363>>
*/
/**
@@ -731,6 +731,24 @@ bool ReactNativeFeatureFlagsAccessor::useRawPropsJsiValue() {
return flagValue.value();
}
bool ReactNativeFeatureFlagsAccessor::useShadowNodeStateOnClone() {
auto flagValue = useShadowNodeStateOnClone_.load();
if (!flagValue.has_value()) {
// This block is not exclusive but it is not necessary.
// If multiple threads try to initialize the feature flag, we would only
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(39, "useShadowNodeStateOnClone");
flagValue = currentProvider_->useShadowNodeStateOnClone();
useShadowNodeStateOnClone_ = flagValue;
}
return flagValue.value();
}
bool ReactNativeFeatureFlagsAccessor::useTurboModuleInterop() {
auto flagValue = useTurboModuleInterop_.load();
@@ -740,7 +758,7 @@ bool ReactNativeFeatureFlagsAccessor::useTurboModuleInterop() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(39, "useTurboModuleInterop");
markFlagAsAccessed(40, "useTurboModuleInterop");
flagValue = currentProvider_->useTurboModuleInterop();
useTurboModuleInterop_ = flagValue;
@@ -758,7 +776,7 @@ bool ReactNativeFeatureFlagsAccessor::useTurboModules() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(40, "useTurboModules");
markFlagAsAccessed(41, "useTurboModules");
flagValue = currentProvider_->useTurboModules();
useTurboModules_ = flagValue;
@@ -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<<ccf8a70c9fdf7a493a8a18e60a1c99e3>>
* @generated SignedSource<<2849b6b0b37b68825d9d9079a6ac5098>>
*/
/**
@@ -71,6 +71,7 @@ class ReactNativeFeatureFlagsAccessor {
bool useNativeViewConfigsInBridgelessMode();
bool useOptimizedEventBatchingOnAndroid();
bool useRawPropsJsiValue();
bool useShadowNodeStateOnClone();
bool useTurboModuleInterop();
bool useTurboModules();
@@ -84,7 +85,7 @@ class ReactNativeFeatureFlagsAccessor {
std::unique_ptr<ReactNativeFeatureFlagsProvider> currentProvider_;
bool wasOverridden_;
std::array<std::atomic<const char*>, 41> accessedFeatureFlags_;
std::array<std::atomic<const char*>, 42> accessedFeatureFlags_;
std::atomic<std::optional<bool>> commonTestFlag_;
std::atomic<std::optional<bool>> animatedShouldSignalBatch_;
@@ -125,6 +126,7 @@ class ReactNativeFeatureFlagsAccessor {
std::atomic<std::optional<bool>> useNativeViewConfigsInBridgelessMode_;
std::atomic<std::optional<bool>> useOptimizedEventBatchingOnAndroid_;
std::atomic<std::optional<bool>> useRawPropsJsiValue_;
std::atomic<std::optional<bool>> useShadowNodeStateOnClone_;
std::atomic<std::optional<bool>> useTurboModuleInterop_;
std::atomic<std::optional<bool>> useTurboModules_;
};
@@ -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<<4e23b010eadf22447ef6ef69465c3949>>
* @generated SignedSource<<377c3de6bcd7de45efa0d58e0de94fb1>>
*/
/**
@@ -183,6 +183,10 @@ class ReactNativeFeatureFlagsDefaults : public ReactNativeFeatureFlagsProvider {
return false;
}
bool useShadowNodeStateOnClone() override {
return false;
}
bool useTurboModuleInterop() override {
return false;
}
@@ -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<<d3e9124f38430340cbe5f13139c497f0>>
* @generated SignedSource<<f23c8066cc50499821cc75220acc3962>>
*/
/**
@@ -396,6 +396,15 @@ class ReactNativeFeatureFlagsDynamicProvider : public ReactNativeFeatureFlagsDef
return ReactNativeFeatureFlagsDefaults::useRawPropsJsiValue();
}
bool useShadowNodeStateOnClone() override {
auto value = values_["useShadowNodeStateOnClone"];
if (!value.isNull()) {
return value.getBool();
}
return ReactNativeFeatureFlagsDefaults::useShadowNodeStateOnClone();
}
bool useTurboModuleInterop() override {
auto value = values_["useTurboModuleInterop"];
if (!value.isNull()) {
@@ -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<<69021ab68d9c8b52f04af8a7f4db22bb>>
* @generated SignedSource<<9dc34d10f6fcfe475b851db7db573015>>
*/
/**
@@ -64,6 +64,7 @@ class ReactNativeFeatureFlagsProvider {
virtual bool useNativeViewConfigsInBridgelessMode() = 0;
virtual bool useOptimizedEventBatchingOnAndroid() = 0;
virtual bool useRawPropsJsiValue() = 0;
virtual bool useShadowNodeStateOnClone() = 0;
virtual bool useTurboModuleInterop() = 0;
virtual bool useTurboModules() = 0;
};
@@ -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<<c2d6e957d5a5107fe16a99d2ab36907c>>
* @generated SignedSource<<35fca1602825c8a7b2e551388e0064cc>>
*/
/**
@@ -239,6 +239,11 @@ bool NativeReactNativeFeatureFlags::useRawPropsJsiValue(
return ReactNativeFeatureFlags::useRawPropsJsiValue();
}
bool NativeReactNativeFeatureFlags::useShadowNodeStateOnClone(
jsi::Runtime& /*runtime*/) {
return ReactNativeFeatureFlags::useShadowNodeStateOnClone();
}
bool NativeReactNativeFeatureFlags::useTurboModuleInterop(
jsi::Runtime& /*runtime*/) {
return ReactNativeFeatureFlags::useTurboModuleInterop();
@@ -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<<5b653b410e1237979cf0c2e1a1bd3610>>
* @generated SignedSource<<176dd9398c3de7438ff6962cd3415dc8>>
*/
/**
@@ -115,6 +115,8 @@ class NativeReactNativeFeatureFlags
bool useRawPropsJsiValue(jsi::Runtime& runtime);
bool useShadowNodeStateOnClone(jsi::Runtime& runtime);
bool useTurboModuleInterop(jsi::Runtime& runtime);
bool useTurboModules(jsi::Runtime& runtime);
@@ -460,6 +460,17 @@ const definitions: FeatureFlagDefinitions = {
},
ossReleaseStage: 'none',
},
useShadowNodeStateOnClone: {
defaultValue: false,
metadata: {
dateAdded: '2025-04-16',
description:
'Use the state stored on the source shadow node when cloning it instead of reading in the most recent state on the shadow node family.',
expectedReleaseValue: true,
purpose: 'experimentation',
},
ossReleaseStage: 'none',
},
useTurboModuleInterop: {
defaultValue: false,
metadata: {
@@ -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<<cadcd9dda2f6c4b0e76dce2c855989a8>>
* @generated SignedSource<<23e97cba20fdf4afc991cbae70c57b1f>>
* @flow strict
*/
@@ -85,6 +85,7 @@ export type ReactNativeFeatureFlags = $ReadOnly<{
useNativeViewConfigsInBridgelessMode: Getter<boolean>,
useOptimizedEventBatchingOnAndroid: Getter<boolean>,
useRawPropsJsiValue: Getter<boolean>,
useShadowNodeStateOnClone: Getter<boolean>,
useTurboModuleInterop: Getter<boolean>,
useTurboModules: Getter<boolean>,
}>;
@@ -309,6 +310,10 @@ export const useOptimizedEventBatchingOnAndroid: Getter<boolean> = createNativeF
* Instead of using folly::dynamic as internal representation in RawProps and RawValue, use jsi::Value
*/
export const useRawPropsJsiValue: Getter<boolean> = createNativeFlagGetter('useRawPropsJsiValue', false);
/**
* Use the state stored on the source shadow node when cloning it instead of reading in the most recent state on the shadow node family.
*/
export const useShadowNodeStateOnClone: Getter<boolean> = createNativeFlagGetter('useShadowNodeStateOnClone', false);
/**
* In Bridgeless mode, should legacy NativeModules use the TurboModule system?
*/
@@ -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<<4c96ee851d662f5984d4512817f5c6c0>>
* @generated SignedSource<<1933fe52e53c0af3d46ea46233ef9e02>>
* @flow strict
*/
@@ -63,6 +63,7 @@ export interface Spec extends TurboModule {
+useNativeViewConfigsInBridgelessMode?: () => boolean;
+useOptimizedEventBatchingOnAndroid?: () => boolean;
+useRawPropsJsiValue?: () => boolean;
+useShadowNodeStateOnClone?: () => boolean;
+useTurboModuleInterop?: () => boolean;
+useTurboModules?: () => boolean;
}