Skip to content

Commit 22a4e06

Browse files
lenaicNick Lefever
andauthored
Backport useShadowNodeStateOnClone and updateRuntimeShadowNodeReferencesOnCommit (and more)
* Add updateRuntimeShadowNodeReferencesOnCommit and useShadowNodeStateOnClone feature flags * Use source shadow node state on clone * Enable useShadowNodeStateOnClone by default on OSS * Split shadow node reference setter and update functionality * Move shadow node reference updates to tree commit * Enable updateRuntimeShadowNodeReferencesOnCommit by default for OSS --------- Co-authored-by: Nick Lefever <[email protected]>
1 parent 994ab4a commit 22a4e06

25 files changed

+300
-32
lines changed

packages/react-native/Libraries/AppDelegate/RCTReactNativeFactory.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,14 @@ bool useNativeViewConfigsInBridgelessMode() override
314314
{
315315
return true;
316316
}
317+
bool updateRuntimeShadowNodeReferencesOnCommit() override
318+
{
319+
return true;
320+
}
321+
bool useShadowNodeStateOnClone() override
322+
{
323+
return true;
324+
}
317325
};
318326

319327
- (void)_setUpFeatureFlags

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

Lines changed: 13 additions & 1 deletion
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<<5e27f8a6852293234595697743315ff8>>
7+
* @generated SignedSource<<b263bdcbc1258f7d5c56e69732ba9076>>
88
*/
99

1010
/**
@@ -238,6 +238,12 @@ public object ReactNativeFeatureFlags {
238238
@JvmStatic
239239
public fun traceTurboModulePromiseRejectionsOnAndroid(): Boolean = accessor.traceTurboModulePromiseRejectionsOnAndroid()
240240

241+
/**
242+
* When enabled, runtime shadow node references will be updated during the commit. This allows running RSNRU from any thread without corrupting the renderer state.
243+
*/
244+
@JvmStatic
245+
public fun updateRuntimeShadowNodeReferencesOnCommit(): Boolean = accessor.updateRuntimeShadowNodeReferencesOnCommit()
246+
241247
/**
242248
* In Bridgeless mode, use the always available javascript error reporting pipeline.
243249
*/
@@ -274,6 +280,12 @@ public object ReactNativeFeatureFlags {
274280
@JvmStatic
275281
public fun useRawPropsJsiValue(): Boolean = accessor.useRawPropsJsiValue()
276282

283+
/**
284+
* 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.
285+
*/
286+
@JvmStatic
287+
public fun useShadowNodeStateOnClone(): Boolean = accessor.useShadowNodeStateOnClone()
288+
277289
/**
278290
* In Bridgeless mode, should legacy NativeModules use the TurboModule system?
279291
*/

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

Lines changed: 21 additions & 1 deletion
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<<b59cecccbe734a126dcd20f76d0ce7c7>>
7+
* @generated SignedSource<<0496ecf3d1e5d8a2e6d4d594aca806d0>>
88
*/
99

1010
/**
@@ -55,12 +55,14 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
5555
private var removeTurboModuleManagerDelegateMutexCache: Boolean? = null
5656
private var throwExceptionInsteadOfDeadlockOnTurboModuleSetupDuringSyncRenderIOSCache: Boolean? = null
5757
private var traceTurboModulePromiseRejectionsOnAndroidCache: Boolean? = null
58+
private var updateRuntimeShadowNodeReferencesOnCommitCache: Boolean? = null
5859
private var useAlwaysAvailableJSErrorHandlingCache: Boolean? = null
5960
private var useEditTextStockAndroidFocusBehaviorCache: Boolean? = null
6061
private var useFabricInteropCache: Boolean? = null
6162
private var useNativeViewConfigsInBridgelessModeCache: Boolean? = null
6263
private var useOptimizedEventBatchingOnAndroidCache: Boolean? = null
6364
private var useRawPropsJsiValueCache: Boolean? = null
65+
private var useShadowNodeStateOnCloneCache: Boolean? = null
6466
private var useTurboModuleInteropCache: Boolean? = null
6567
private var useTurboModulesCache: Boolean? = null
6668

@@ -379,6 +381,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
379381
return cached
380382
}
381383

384+
override fun updateRuntimeShadowNodeReferencesOnCommit(): Boolean {
385+
var cached = updateRuntimeShadowNodeReferencesOnCommitCache
386+
if (cached == null) {
387+
cached = ReactNativeFeatureFlagsCxxInterop.updateRuntimeShadowNodeReferencesOnCommit()
388+
updateRuntimeShadowNodeReferencesOnCommitCache = cached
389+
}
390+
return cached
391+
}
392+
382393
override fun useAlwaysAvailableJSErrorHandling(): Boolean {
383394
var cached = useAlwaysAvailableJSErrorHandlingCache
384395
if (cached == null) {
@@ -433,6 +444,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
433444
return cached
434445
}
435446

447+
override fun useShadowNodeStateOnClone(): Boolean {
448+
var cached = useShadowNodeStateOnCloneCache
449+
if (cached == null) {
450+
cached = ReactNativeFeatureFlagsCxxInterop.useShadowNodeStateOnClone()
451+
useShadowNodeStateOnCloneCache = cached
452+
}
453+
return cached
454+
}
455+
436456
override fun useTurboModuleInterop(): Boolean {
437457
var cached = useTurboModuleInteropCache
438458
if (cached == null) {

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

Lines changed: 5 additions & 1 deletion
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<<08b51adfc7c09f0f26f2b3c8351cda01>>
7+
* @generated SignedSource<<c4f3b0cee8b9b4b9cebb589801e1dd15>>
88
*/
99

1010
/**
@@ -98,6 +98,8 @@ public object ReactNativeFeatureFlagsCxxInterop {
9898

9999
@DoNotStrip @JvmStatic public external fun traceTurboModulePromiseRejectionsOnAndroid(): Boolean
100100

101+
@DoNotStrip @JvmStatic public external fun updateRuntimeShadowNodeReferencesOnCommit(): Boolean
102+
101103
@DoNotStrip @JvmStatic public external fun useAlwaysAvailableJSErrorHandling(): Boolean
102104

103105
@DoNotStrip @JvmStatic public external fun useEditTextStockAndroidFocusBehavior(): Boolean
@@ -110,6 +112,8 @@ public object ReactNativeFeatureFlagsCxxInterop {
110112

111113
@DoNotStrip @JvmStatic public external fun useRawPropsJsiValue(): Boolean
112114

115+
@DoNotStrip @JvmStatic public external fun useShadowNodeStateOnClone(): Boolean
116+
113117
@DoNotStrip @JvmStatic public external fun useTurboModuleInterop(): Boolean
114118

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

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

Lines changed: 5 additions & 1 deletion
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<<0041e37961e68474a6d092dc0f8a4903>>
7+
* @generated SignedSource<<a8900217ae0385947b619c8fa0834942>>
88
*/
99

1010
/**
@@ -93,6 +93,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
9393

9494
override fun traceTurboModulePromiseRejectionsOnAndroid(): Boolean = false
9595

96+
override fun updateRuntimeShadowNodeReferencesOnCommit(): Boolean = false
97+
9698
override fun useAlwaysAvailableJSErrorHandling(): Boolean = false
9799

98100
override fun useEditTextStockAndroidFocusBehavior(): Boolean = true
@@ -105,6 +107,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
105107

106108
override fun useRawPropsJsiValue(): Boolean = false
107109

110+
override fun useShadowNodeStateOnClone(): Boolean = false
111+
108112
override fun useTurboModuleInterop(): Boolean = false
109113

110114
override fun useTurboModules(): Boolean = false

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

Lines changed: 23 additions & 1 deletion
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<<e5c1e722f33148fe3aa36ccab62e2293>>
7+
* @generated SignedSource<<8f5180a0ef154c083ac38d28e650ee11>>
88
*/
99

1010
/**
@@ -59,12 +59,14 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
5959
private var removeTurboModuleManagerDelegateMutexCache: Boolean? = null
6060
private var throwExceptionInsteadOfDeadlockOnTurboModuleSetupDuringSyncRenderIOSCache: Boolean? = null
6161
private var traceTurboModulePromiseRejectionsOnAndroidCache: Boolean? = null
62+
private var updateRuntimeShadowNodeReferencesOnCommitCache: Boolean? = null
6263
private var useAlwaysAvailableJSErrorHandlingCache: Boolean? = null
6364
private var useEditTextStockAndroidFocusBehaviorCache: Boolean? = null
6465
private var useFabricInteropCache: Boolean? = null
6566
private var useNativeViewConfigsInBridgelessModeCache: Boolean? = null
6667
private var useOptimizedEventBatchingOnAndroidCache: Boolean? = null
6768
private var useRawPropsJsiValueCache: Boolean? = null
69+
private var useShadowNodeStateOnCloneCache: Boolean? = null
6870
private var useTurboModuleInteropCache: Boolean? = null
6971
private var useTurboModulesCache: Boolean? = null
7072

@@ -418,6 +420,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
418420
return cached
419421
}
420422

423+
override fun updateRuntimeShadowNodeReferencesOnCommit(): Boolean {
424+
var cached = updateRuntimeShadowNodeReferencesOnCommitCache
425+
if (cached == null) {
426+
cached = currentProvider.updateRuntimeShadowNodeReferencesOnCommit()
427+
accessedFeatureFlags.add("updateRuntimeShadowNodeReferencesOnCommit")
428+
updateRuntimeShadowNodeReferencesOnCommitCache = cached
429+
}
430+
return cached
431+
}
432+
421433
override fun useAlwaysAvailableJSErrorHandling(): Boolean {
422434
var cached = useAlwaysAvailableJSErrorHandlingCache
423435
if (cached == null) {
@@ -478,6 +490,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
478490
return cached
479491
}
480492

493+
override fun useShadowNodeStateOnClone(): Boolean {
494+
var cached = useShadowNodeStateOnCloneCache
495+
if (cached == null) {
496+
cached = currentProvider.useShadowNodeStateOnClone()
497+
accessedFeatureFlags.add("useShadowNodeStateOnClone")
498+
useShadowNodeStateOnCloneCache = cached
499+
}
500+
return cached
501+
}
502+
481503
override fun useTurboModuleInterop(): Boolean {
482504
var cached = useTurboModuleInteropCache
483505
if (cached == null) {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsOverrides_RNOSS_Stable_Android.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@ public class ReactNativeFeatureFlagsOverrides_RNOSS_Stable_Android(
1717
override fun enableFabricRenderer(): Boolean = bridgelessEnabled || fabricEnabled
1818

1919
override fun useTurboModules(): Boolean = bridgelessEnabled || turboModulesEnabled
20+
21+
override fun updateRuntimeShadowNodeReferencesOnCommit(): Boolean = true
22+
23+
override fun useShadowNodeStateOnClone(): Boolean = true
2024
}

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

Lines changed: 5 additions & 1 deletion
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<<9a223b4f79e4612eb193036256bfebc5>>
7+
* @generated SignedSource<<33571f99b1f78fbc62cecfca5f8351fa>>
88
*/
99

1010
/**
@@ -93,6 +93,8 @@ public interface ReactNativeFeatureFlagsProvider {
9393

9494
@DoNotStrip public fun traceTurboModulePromiseRejectionsOnAndroid(): Boolean
9595

96+
@DoNotStrip public fun updateRuntimeShadowNodeReferencesOnCommit(): Boolean
97+
9698
@DoNotStrip public fun useAlwaysAvailableJSErrorHandling(): Boolean
9799

98100
@DoNotStrip public fun useEditTextStockAndroidFocusBehavior(): Boolean
@@ -105,6 +107,8 @@ public interface ReactNativeFeatureFlagsProvider {
105107

106108
@DoNotStrip public fun useRawPropsJsiValue(): Boolean
107109

110+
@DoNotStrip public fun useShadowNodeStateOnClone(): Boolean
111+
108112
@DoNotStrip public fun useTurboModuleInterop(): Boolean
109113

110114
@DoNotStrip public fun useTurboModules(): Boolean

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

Lines changed: 29 additions & 1 deletion
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<<91c1a65790aa5946a354ab8a1966a5f4>>
7+
* @generated SignedSource<<83b23039ed9fff5109ff3b532648baac>>
88
*/
99

1010
/**
@@ -249,6 +249,12 @@ class ReactNativeFeatureFlagsProviderHolder
249249
return method(javaProvider_);
250250
}
251251

252+
bool updateRuntimeShadowNodeReferencesOnCommit() override {
253+
static const auto method =
254+
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("updateRuntimeShadowNodeReferencesOnCommit");
255+
return method(javaProvider_);
256+
}
257+
252258
bool useAlwaysAvailableJSErrorHandling() override {
253259
static const auto method =
254260
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("useAlwaysAvailableJSErrorHandling");
@@ -285,6 +291,12 @@ class ReactNativeFeatureFlagsProviderHolder
285291
return method(javaProvider_);
286292
}
287293

294+
bool useShadowNodeStateOnClone() override {
295+
static const auto method =
296+
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("useShadowNodeStateOnClone");
297+
return method(javaProvider_);
298+
}
299+
288300
bool useTurboModuleInterop() override {
289301
static const auto method =
290302
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("useTurboModuleInterop");
@@ -476,6 +488,11 @@ bool JReactNativeFeatureFlagsCxxInterop::traceTurboModulePromiseRejectionsOnAndr
476488
return ReactNativeFeatureFlags::traceTurboModulePromiseRejectionsOnAndroid();
477489
}
478490

491+
bool JReactNativeFeatureFlagsCxxInterop::updateRuntimeShadowNodeReferencesOnCommit(
492+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
493+
return ReactNativeFeatureFlags::updateRuntimeShadowNodeReferencesOnCommit();
494+
}
495+
479496
bool JReactNativeFeatureFlagsCxxInterop::useAlwaysAvailableJSErrorHandling(
480497
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
481498
return ReactNativeFeatureFlags::useAlwaysAvailableJSErrorHandling();
@@ -506,6 +523,11 @@ bool JReactNativeFeatureFlagsCxxInterop::useRawPropsJsiValue(
506523
return ReactNativeFeatureFlags::useRawPropsJsiValue();
507524
}
508525

526+
bool JReactNativeFeatureFlagsCxxInterop::useShadowNodeStateOnClone(
527+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
528+
return ReactNativeFeatureFlags::useShadowNodeStateOnClone();
529+
}
530+
509531
bool JReactNativeFeatureFlagsCxxInterop::useTurboModuleInterop(
510532
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
511533
return ReactNativeFeatureFlags::useTurboModuleInterop();
@@ -652,6 +674,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
652674
makeNativeMethod(
653675
"traceTurboModulePromiseRejectionsOnAndroid",
654676
JReactNativeFeatureFlagsCxxInterop::traceTurboModulePromiseRejectionsOnAndroid),
677+
makeNativeMethod(
678+
"updateRuntimeShadowNodeReferencesOnCommit",
679+
JReactNativeFeatureFlagsCxxInterop::updateRuntimeShadowNodeReferencesOnCommit),
655680
makeNativeMethod(
656681
"useAlwaysAvailableJSErrorHandling",
657682
JReactNativeFeatureFlagsCxxInterop::useAlwaysAvailableJSErrorHandling),
@@ -670,6 +695,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
670695
makeNativeMethod(
671696
"useRawPropsJsiValue",
672697
JReactNativeFeatureFlagsCxxInterop::useRawPropsJsiValue),
698+
makeNativeMethod(
699+
"useShadowNodeStateOnClone",
700+
JReactNativeFeatureFlagsCxxInterop::useShadowNodeStateOnClone),
673701
makeNativeMethod(
674702
"useTurboModuleInterop",
675703
JReactNativeFeatureFlagsCxxInterop::useTurboModuleInterop),

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

Lines changed: 7 additions & 1 deletion
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<<610104213a5eba23b797e27377d71b52>>
7+
* @generated SignedSource<<efb0288fd19fb35e4582522c835301b4>>
88
*/
99

1010
/**
@@ -135,6 +135,9 @@ class JReactNativeFeatureFlagsCxxInterop
135135
static bool traceTurboModulePromiseRejectionsOnAndroid(
136136
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
137137

138+
static bool updateRuntimeShadowNodeReferencesOnCommit(
139+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
140+
138141
static bool useAlwaysAvailableJSErrorHandling(
139142
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
140143

@@ -153,6 +156,9 @@ class JReactNativeFeatureFlagsCxxInterop
153156
static bool useRawPropsJsiValue(
154157
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
155158

159+
static bool useShadowNodeStateOnClone(
160+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
161+
156162
static bool useTurboModuleInterop(
157163
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
158164

0 commit comments

Comments
 (0)