Skip to content

Commit 10c60cc

Browse files
Nick Lefeveruffoltzl
Nick Lefever
authored and
uffoltzl
committed
Add feature flag for using shadow node state on clone (facebook#50751)
Summary: Pull Request resolved: facebook#50751 See title Changelog: [Internal] Reviewed By: rshest Differential Revision: D73067007 fbshipit-source-id: 2a67ed33ebd35ffaa3470d75ef6f695471820fa6
1 parent ff9b17e commit 10c60cc

20 files changed

+139
-22
lines changed

Diff for: packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<745904568803a9ead98bc10210b38938>>
7+
* @generated SignedSource<<794bf258fbb453ea71a39c5459316a24>>
88
*/
99

1010
/**
@@ -264,6 +264,12 @@ public object ReactNativeFeatureFlags {
264264
@JvmStatic
265265
public fun useRawPropsJsiValue(): Boolean = accessor.useRawPropsJsiValue()
266266

267+
/**
268+
* 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.
269+
*/
270+
@JvmStatic
271+
public fun useShadowNodeStateOnClone(): Boolean = accessor.useShadowNodeStateOnClone()
272+
267273
/**
268274
* In Bridgeless mode, should legacy NativeModules use the TurboModule system?
269275
*/

Diff for: packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<4f9df3bdf8c353ccbdfeea0f0d378e01>>
7+
* @generated SignedSource<<43260e9f0b5774bdb3d60915bcd28ea3>>
88
*/
99

1010
/**
@@ -59,6 +59,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
5959
private var useNativeViewConfigsInBridgelessModeCache: Boolean? = null
6060
private var useOptimizedEventBatchingOnAndroidCache: Boolean? = null
6161
private var useRawPropsJsiValueCache: Boolean? = null
62+
private var useShadowNodeStateOnCloneCache: Boolean? = null
6263
private var useTurboModuleInteropCache: Boolean? = null
6364
private var useTurboModulesCache: Boolean? = null
6465

@@ -413,6 +414,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
413414
return cached
414415
}
415416

417+
override fun useShadowNodeStateOnClone(): Boolean {
418+
var cached = useShadowNodeStateOnCloneCache
419+
if (cached == null) {
420+
cached = ReactNativeFeatureFlagsCxxInterop.useShadowNodeStateOnClone()
421+
useShadowNodeStateOnCloneCache = cached
422+
}
423+
return cached
424+
}
425+
416426
override fun useTurboModuleInterop(): Boolean {
417427
var cached = useTurboModuleInteropCache
418428
if (cached == null) {

Diff for: packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<8200512b24c8ddd99e582b24e858f1f8>>
7+
* @generated SignedSource<<1f3845a6aad6babd4404adfb433f4b38>>
88
*/
99

1010
/**
@@ -106,6 +106,8 @@ public object ReactNativeFeatureFlagsCxxInterop {
106106

107107
@DoNotStrip @JvmStatic public external fun useRawPropsJsiValue(): Boolean
108108

109+
@DoNotStrip @JvmStatic public external fun useShadowNodeStateOnClone(): Boolean
110+
109111
@DoNotStrip @JvmStatic public external fun useTurboModuleInterop(): Boolean
110112

111113
@DoNotStrip @JvmStatic public external fun useTurboModules(): Boolean

Diff for: packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<92ac1a25b3c5eb4e43334e0c65e5255f>>
7+
* @generated SignedSource<<6f24701d1581b744185caaee1ca5fc06>>
88
*/
99

1010
/**
@@ -101,6 +101,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
101101

102102
override fun useRawPropsJsiValue(): Boolean = false
103103

104+
override fun useShadowNodeStateOnClone(): Boolean = false
105+
104106
override fun useTurboModuleInterop(): Boolean = false
105107

106108
override fun useTurboModules(): Boolean = false

Diff for: packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt

+12-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<c7d8c0c6ff5a50925692cca2de48c537>>
7+
* @generated SignedSource<<8988a69695658c92f013e736dec8f5fc>>
88
*/
99

1010
/**
@@ -63,6 +63,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
6363
private var useNativeViewConfigsInBridgelessModeCache: Boolean? = null
6464
private var useOptimizedEventBatchingOnAndroidCache: Boolean? = null
6565
private var useRawPropsJsiValueCache: Boolean? = null
66+
private var useShadowNodeStateOnCloneCache: Boolean? = null
6667
private var useTurboModuleInteropCache: Boolean? = null
6768
private var useTurboModulesCache: Boolean? = null
6869

@@ -456,6 +457,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
456457
return cached
457458
}
458459

460+
override fun useShadowNodeStateOnClone(): Boolean {
461+
var cached = useShadowNodeStateOnCloneCache
462+
if (cached == null) {
463+
cached = currentProvider.useShadowNodeStateOnClone()
464+
accessedFeatureFlags.add("useShadowNodeStateOnClone")
465+
useShadowNodeStateOnCloneCache = cached
466+
}
467+
return cached
468+
}
469+
459470
override fun useTurboModuleInterop(): Boolean {
460471
var cached = useTurboModuleInteropCache
461472
if (cached == null) {

Diff for: packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<54e0deb6c78833a3f0394d4ff2ab9562>>
7+
* @generated SignedSource<<646efad3c8769005e893ad63d78b8c6c>>
88
*/
99

1010
/**
@@ -101,6 +101,8 @@ public interface ReactNativeFeatureFlagsProvider {
101101

102102
@DoNotStrip public fun useRawPropsJsiValue(): Boolean
103103

104+
@DoNotStrip public fun useShadowNodeStateOnClone(): Boolean
105+
104106
@DoNotStrip public fun useTurboModuleInterop(): Boolean
105107

106108
@DoNotStrip public fun useTurboModules(): Boolean

Diff for: packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<d944ced839aa053484befb1496749b9e>>
7+
* @generated SignedSource<<cfbc50cc7a2ce2dbff3447c697d45797>>
88
*/
99

1010
/**
@@ -273,6 +273,12 @@ class ReactNativeFeatureFlagsJavaProvider
273273
return method(javaProvider_);
274274
}
275275

276+
bool useShadowNodeStateOnClone() override {
277+
static const auto method =
278+
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("useShadowNodeStateOnClone");
279+
return method(javaProvider_);
280+
}
281+
276282
bool useTurboModuleInterop() override {
277283
static const auto method =
278284
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("useTurboModuleInterop");
@@ -484,6 +490,11 @@ bool JReactNativeFeatureFlagsCxxInterop::useRawPropsJsiValue(
484490
return ReactNativeFeatureFlags::useRawPropsJsiValue();
485491
}
486492

493+
bool JReactNativeFeatureFlagsCxxInterop::useShadowNodeStateOnClone(
494+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
495+
return ReactNativeFeatureFlags::useShadowNodeStateOnClone();
496+
}
497+
487498
bool JReactNativeFeatureFlagsCxxInterop::useTurboModuleInterop(
488499
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
489500
return ReactNativeFeatureFlags::useTurboModuleInterop();
@@ -642,6 +653,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
642653
makeNativeMethod(
643654
"useRawPropsJsiValue",
644655
JReactNativeFeatureFlagsCxxInterop::useRawPropsJsiValue),
656+
makeNativeMethod(
657+
"useShadowNodeStateOnClone",
658+
JReactNativeFeatureFlagsCxxInterop::useShadowNodeStateOnClone),
645659
makeNativeMethod(
646660
"useTurboModuleInterop",
647661
JReactNativeFeatureFlagsCxxInterop::useTurboModuleInterop),

Diff for: packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<c122826c2dd42cfb66e96e1af5c7a54a>>
7+
* @generated SignedSource<<58c3ec4bdf7b171ea6203ed100116c50>>
88
*/
99

1010
/**
@@ -147,6 +147,9 @@ class JReactNativeFeatureFlagsCxxInterop
147147
static bool useRawPropsJsiValue(
148148
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
149149

150+
static bool useShadowNodeStateOnClone(
151+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
152+
150153
static bool useTurboModuleInterop(
151154
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
152155

Diff for: packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<f98498698a19d59cc4113bf6bbc0b2ea>>
7+
* @generated SignedSource<<55680628f0480fce8c955fbde539ae47>>
88
*/
99

1010
/**
@@ -182,6 +182,10 @@ bool ReactNativeFeatureFlags::useRawPropsJsiValue() {
182182
return getAccessor().useRawPropsJsiValue();
183183
}
184184

185+
bool ReactNativeFeatureFlags::useShadowNodeStateOnClone() {
186+
return getAccessor().useShadowNodeStateOnClone();
187+
}
188+
185189
bool ReactNativeFeatureFlags::useTurboModuleInterop() {
186190
return getAccessor().useTurboModuleInterop();
187191
}

Diff for: packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<aa1cc3b66b13bf529e06239c018ad515>>
7+
* @generated SignedSource<<136de88435026f3bfb2d785d1a12b707>>
88
*/
99

1010
/**
@@ -234,6 +234,11 @@ class ReactNativeFeatureFlags {
234234
*/
235235
RN_EXPORT static bool useRawPropsJsiValue();
236236

237+
/**
238+
* 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.
239+
*/
240+
RN_EXPORT static bool useShadowNodeStateOnClone();
241+
237242
/**
238243
* In Bridgeless mode, should legacy NativeModules use the TurboModule system?
239244
*/

Diff for: packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.cpp

+21-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<ed39775341d5f6a93d8c5974309eb9b4>>
7+
* @generated SignedSource<<6f18b18b4aa1ef98f94bf4f595a59363>>
88
*/
99

1010
/**
@@ -731,6 +731,24 @@ bool ReactNativeFeatureFlagsAccessor::useRawPropsJsiValue() {
731731
return flagValue.value();
732732
}
733733

734+
bool ReactNativeFeatureFlagsAccessor::useShadowNodeStateOnClone() {
735+
auto flagValue = useShadowNodeStateOnClone_.load();
736+
737+
if (!flagValue.has_value()) {
738+
// This block is not exclusive but it is not necessary.
739+
// If multiple threads try to initialize the feature flag, we would only
740+
// be accessing the provider multiple times but the end state of this
741+
// instance and the returned flag value would be the same.
742+
743+
markFlagAsAccessed(39, "useShadowNodeStateOnClone");
744+
745+
flagValue = currentProvider_->useShadowNodeStateOnClone();
746+
useShadowNodeStateOnClone_ = flagValue;
747+
}
748+
749+
return flagValue.value();
750+
}
751+
734752
bool ReactNativeFeatureFlagsAccessor::useTurboModuleInterop() {
735753
auto flagValue = useTurboModuleInterop_.load();
736754

@@ -740,7 +758,7 @@ bool ReactNativeFeatureFlagsAccessor::useTurboModuleInterop() {
740758
// be accessing the provider multiple times but the end state of this
741759
// instance and the returned flag value would be the same.
742760

743-
markFlagAsAccessed(39, "useTurboModuleInterop");
761+
markFlagAsAccessed(40, "useTurboModuleInterop");
744762

745763
flagValue = currentProvider_->useTurboModuleInterop();
746764
useTurboModuleInterop_ = flagValue;
@@ -758,7 +776,7 @@ bool ReactNativeFeatureFlagsAccessor::useTurboModules() {
758776
// be accessing the provider multiple times but the end state of this
759777
// instance and the returned flag value would be the same.
760778

761-
markFlagAsAccessed(40, "useTurboModules");
779+
markFlagAsAccessed(41, "useTurboModules");
762780

763781
flagValue = currentProvider_->useTurboModules();
764782
useTurboModules_ = flagValue;

Diff for: packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<ccf8a70c9fdf7a493a8a18e60a1c99e3>>
7+
* @generated SignedSource<<2849b6b0b37b68825d9d9079a6ac5098>>
88
*/
99

1010
/**
@@ -71,6 +71,7 @@ class ReactNativeFeatureFlagsAccessor {
7171
bool useNativeViewConfigsInBridgelessMode();
7272
bool useOptimizedEventBatchingOnAndroid();
7373
bool useRawPropsJsiValue();
74+
bool useShadowNodeStateOnClone();
7475
bool useTurboModuleInterop();
7576
bool useTurboModules();
7677

@@ -84,7 +85,7 @@ class ReactNativeFeatureFlagsAccessor {
8485
std::unique_ptr<ReactNativeFeatureFlagsProvider> currentProvider_;
8586
bool wasOverridden_;
8687

87-
std::array<std::atomic<const char*>, 41> accessedFeatureFlags_;
88+
std::array<std::atomic<const char*>, 42> accessedFeatureFlags_;
8889

8990
std::atomic<std::optional<bool>> commonTestFlag_;
9091
std::atomic<std::optional<bool>> animatedShouldSignalBatch_;
@@ -125,6 +126,7 @@ class ReactNativeFeatureFlagsAccessor {
125126
std::atomic<std::optional<bool>> useNativeViewConfigsInBridgelessMode_;
126127
std::atomic<std::optional<bool>> useOptimizedEventBatchingOnAndroid_;
127128
std::atomic<std::optional<bool>> useRawPropsJsiValue_;
129+
std::atomic<std::optional<bool>> useShadowNodeStateOnClone_;
128130
std::atomic<std::optional<bool>> useTurboModuleInterop_;
129131
std::atomic<std::optional<bool>> useTurboModules_;
130132
};

Diff for: packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<4e23b010eadf22447ef6ef69465c3949>>
7+
* @generated SignedSource<<377c3de6bcd7de45efa0d58e0de94fb1>>
88
*/
99

1010
/**
@@ -183,6 +183,10 @@ class ReactNativeFeatureFlagsDefaults : public ReactNativeFeatureFlagsProvider {
183183
return false;
184184
}
185185

186+
bool useShadowNodeStateOnClone() override {
187+
return false;
188+
}
189+
186190
bool useTurboModuleInterop() override {
187191
return false;
188192
}

Diff for: packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDynamicProvider.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<d3e9124f38430340cbe5f13139c497f0>>
7+
* @generated SignedSource<<f23c8066cc50499821cc75220acc3962>>
88
*/
99

1010
/**
@@ -396,6 +396,15 @@ class ReactNativeFeatureFlagsDynamicProvider : public ReactNativeFeatureFlagsDef
396396
return ReactNativeFeatureFlagsDefaults::useRawPropsJsiValue();
397397
}
398398

399+
bool useShadowNodeStateOnClone() override {
400+
auto value = values_["useShadowNodeStateOnClone"];
401+
if (!value.isNull()) {
402+
return value.getBool();
403+
}
404+
405+
return ReactNativeFeatureFlagsDefaults::useShadowNodeStateOnClone();
406+
}
407+
399408
bool useTurboModuleInterop() override {
400409
auto value = values_["useTurboModuleInterop"];
401410
if (!value.isNull()) {

Diff for: packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsProvider.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<69021ab68d9c8b52f04af8a7f4db22bb>>
7+
* @generated SignedSource<<9dc34d10f6fcfe475b851db7db573015>>
88
*/
99

1010
/**
@@ -64,6 +64,7 @@ class ReactNativeFeatureFlagsProvider {
6464
virtual bool useNativeViewConfigsInBridgelessMode() = 0;
6565
virtual bool useOptimizedEventBatchingOnAndroid() = 0;
6666
virtual bool useRawPropsJsiValue() = 0;
67+
virtual bool useShadowNodeStateOnClone() = 0;
6768
virtual bool useTurboModuleInterop() = 0;
6869
virtual bool useTurboModules() = 0;
6970
};

0 commit comments

Comments
 (0)