Skip to content

Commit 5042e58

Browse files
fkgozalimeta-codesync[bot]
authored andcommitted
Fix parentTagForUpdate in unflatten-unflatten branch (#56542)
Summary: Pull Request resolved: #56542 Fix incorrect parentTag passed as parentTagForUpdate in the unflatten-unflatten branch of calculateShadowViewMutationsFlattener. In the unflatten case, parentTag references a node being created in the same batch, but UPDATE mutations are flushed at position 2 while Creates are at position 5. This causes the UPDATE to reference a parent that does not exist yet, triggering an assertion failure in StubViewTree::mutate(): `oldStubView->parentTag == mutation.parentTag`. The fix changes `parentTag` to `parentTagForUpdate` in the recursive call at line 684, gated behind a new feature flag `fixDifferentiatorParentTagForUnflattenCase` for safe rollout. Changelog: [Internal] Reviewed By: javache Differential Revision: D101508791 fbshipit-source-id: 646d7e3b19bf186eeadc501452ce40ee82857b40
1 parent 5c55a61 commit 5042e58

22 files changed

Lines changed: 388 additions & 55 deletions

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

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<<99a7d3e814f4b037ed4496b6eee4f264>>
7+
* @generated SignedSource<<4ee7b2e0a88bc5087e0739658810dee5>>
88
*/
99

1010
/**
@@ -360,6 +360,12 @@ public object ReactNativeFeatureFlags {
360360
@JvmStatic
361361
public fun enableVirtualViewDebugFeatures(): Boolean = accessor.enableVirtualViewDebugFeatures()
362362

363+
/**
364+
* Fix incorrect parentTag passed as parentTagForUpdate in the unflatten-unflatten branch of calculateShadowViewMutationsFlattener, which causes UPDATE mutations to reference a parent being created in the same batch.
365+
*/
366+
@JvmStatic
367+
public fun fixDifferentiatorParentTagForUnflattenCase(): Boolean = accessor.fixDifferentiatorParentTagForUnflattenCase()
368+
363369
/**
364370
* Fix a use-after-free race condition in findShadowNodeByTag_DEPRECATED by using getCurrentRevision() instead of tryCommit() with a raw pointer.
365371
*/

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

Lines changed: 11 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<<c2f867597d97dc97c8ded5fbd258c13c>>
7+
* @generated SignedSource<<87405910d0abf422badc45d1510ad702>>
88
*/
99

1010
/**
@@ -75,6 +75,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
7575
private var enableViewRecyclingForViewCache: Boolean? = null
7676
private var enableVirtualViewContainerStateExperimentalCache: Boolean? = null
7777
private var enableVirtualViewDebugFeaturesCache: Boolean? = null
78+
private var fixDifferentiatorParentTagForUnflattenCaseCache: Boolean? = null
7879
private var fixFindShadowNodeByTagRaceConditionCache: Boolean? = null
7980
private var fixMappingOfEventPrioritiesBetweenFabricAndReactCache: Boolean? = null
8081
private var fixYogaFlexBasisFitContentInMainAxisCache: Boolean? = null
@@ -605,6 +606,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
605606
return cached
606607
}
607608

609+
override fun fixDifferentiatorParentTagForUnflattenCase(): Boolean {
610+
var cached = fixDifferentiatorParentTagForUnflattenCaseCache
611+
if (cached == null) {
612+
cached = ReactNativeFeatureFlagsCxxInterop.fixDifferentiatorParentTagForUnflattenCase()
613+
fixDifferentiatorParentTagForUnflattenCaseCache = cached
614+
}
615+
return cached
616+
}
617+
608618
override fun fixFindShadowNodeByTagRaceCondition(): Boolean {
609619
var cached = fixFindShadowNodeByTagRaceConditionCache
610620
if (cached == null) {

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

Lines changed: 3 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<<8667d7237cea82bb5978cb19582d59c0>>
7+
* @generated SignedSource<<c0f1210cabc66cc1b3fdbf8473d1df11>>
88
*/
99

1010
/**
@@ -138,6 +138,8 @@ public object ReactNativeFeatureFlagsCxxInterop {
138138

139139
@DoNotStrip @JvmStatic public external fun enableVirtualViewDebugFeatures(): Boolean
140140

141+
@DoNotStrip @JvmStatic public external fun fixDifferentiatorParentTagForUnflattenCase(): Boolean
142+
141143
@DoNotStrip @JvmStatic public external fun fixFindShadowNodeByTagRaceCondition(): Boolean
142144

143145
@DoNotStrip @JvmStatic public external fun fixMappingOfEventPrioritiesBetweenFabricAndReact(): Boolean

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

Lines changed: 3 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<<17abc72a4045c5695818f254be1783b5>>
7+
* @generated SignedSource<<73ce7f74a1fc0843a91d2fe11615b333>>
88
*/
99

1010
/**
@@ -133,6 +133,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
133133

134134
override fun enableVirtualViewDebugFeatures(): Boolean = false
135135

136+
override fun fixDifferentiatorParentTagForUnflattenCase(): Boolean = false
137+
136138
override fun fixFindShadowNodeByTagRaceCondition(): Boolean = false
137139

138140
override fun fixMappingOfEventPrioritiesBetweenFabricAndReact(): Boolean = false

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

Lines changed: 12 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<<77ba6c5db120016e6e1f8af195ab3690>>
7+
* @generated SignedSource<<a070acdbab967adb2c8c81e9e89b8636>>
88
*/
99

1010
/**
@@ -79,6 +79,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
7979
private var enableViewRecyclingForViewCache: Boolean? = null
8080
private var enableVirtualViewContainerStateExperimentalCache: Boolean? = null
8181
private var enableVirtualViewDebugFeaturesCache: Boolean? = null
82+
private var fixDifferentiatorParentTagForUnflattenCaseCache: Boolean? = null
8283
private var fixFindShadowNodeByTagRaceConditionCache: Boolean? = null
8384
private var fixMappingOfEventPrioritiesBetweenFabricAndReactCache: Boolean? = null
8485
private var fixYogaFlexBasisFitContentInMainAxisCache: Boolean? = null
@@ -664,6 +665,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
664665
return cached
665666
}
666667

668+
override fun fixDifferentiatorParentTagForUnflattenCase(): Boolean {
669+
var cached = fixDifferentiatorParentTagForUnflattenCaseCache
670+
if (cached == null) {
671+
cached = currentProvider.fixDifferentiatorParentTagForUnflattenCase()
672+
accessedFeatureFlags.add("fixDifferentiatorParentTagForUnflattenCase")
673+
fixDifferentiatorParentTagForUnflattenCaseCache = cached
674+
}
675+
return cached
676+
}
677+
667678
override fun fixFindShadowNodeByTagRaceCondition(): Boolean {
668679
var cached = fixFindShadowNodeByTagRaceConditionCache
669680
if (cached == null) {

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

Lines changed: 3 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<<8496c138ce5493df84149940df0de944>>
7+
* @generated SignedSource<<2de065dd6f726ad92376e2385e134c7e>>
88
*/
99

1010
/**
@@ -133,6 +133,8 @@ public interface ReactNativeFeatureFlagsProvider {
133133

134134
@DoNotStrip public fun enableVirtualViewDebugFeatures(): Boolean
135135

136+
@DoNotStrip public fun fixDifferentiatorParentTagForUnflattenCase(): Boolean
137+
136138
@DoNotStrip public fun fixFindShadowNodeByTagRaceCondition(): Boolean
137139

138140
@DoNotStrip public fun fixMappingOfEventPrioritiesBetweenFabricAndReact(): Boolean

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

Lines changed: 15 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<<5bac13bb6faeffdd3c5eca800f25b96a>>
7+
* @generated SignedSource<<2c9c4c2ef57882df723930daa933afd8>>
88
*/
99

1010
/**
@@ -369,6 +369,12 @@ class ReactNativeFeatureFlagsJavaProvider
369369
return method(javaProvider_);
370370
}
371371

372+
bool fixDifferentiatorParentTagForUnflattenCase() override {
373+
static const auto method =
374+
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("fixDifferentiatorParentTagForUnflattenCase");
375+
return method(javaProvider_);
376+
}
377+
372378
bool fixFindShadowNodeByTagRaceCondition() override {
373379
static const auto method =
374380
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("fixFindShadowNodeByTagRaceCondition");
@@ -852,6 +858,11 @@ bool JReactNativeFeatureFlagsCxxInterop::enableVirtualViewDebugFeatures(
852858
return ReactNativeFeatureFlags::enableVirtualViewDebugFeatures();
853859
}
854860

861+
bool JReactNativeFeatureFlagsCxxInterop::fixDifferentiatorParentTagForUnflattenCase(
862+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
863+
return ReactNativeFeatureFlags::fixDifferentiatorParentTagForUnflattenCase();
864+
}
865+
855866
bool JReactNativeFeatureFlagsCxxInterop::fixFindShadowNodeByTagRaceCondition(
856867
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
857868
return ReactNativeFeatureFlags::fixFindShadowNodeByTagRaceCondition();
@@ -1218,6 +1229,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
12181229
makeNativeMethod(
12191230
"enableVirtualViewDebugFeatures",
12201231
JReactNativeFeatureFlagsCxxInterop::enableVirtualViewDebugFeatures),
1232+
makeNativeMethod(
1233+
"fixDifferentiatorParentTagForUnflattenCase",
1234+
JReactNativeFeatureFlagsCxxInterop::fixDifferentiatorParentTagForUnflattenCase),
12211235
makeNativeMethod(
12221236
"fixFindShadowNodeByTagRaceCondition",
12231237
JReactNativeFeatureFlagsCxxInterop::fixFindShadowNodeByTagRaceCondition),

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

Lines changed: 4 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<<ad45dce1fafd3bd29078bd54e4206d9f>>
7+
* @generated SignedSource<<d27bc9bf87498e16dff7eac56d52b9d1>>
88
*/
99

1010
/**
@@ -195,6 +195,9 @@ class JReactNativeFeatureFlagsCxxInterop
195195
static bool enableVirtualViewDebugFeatures(
196196
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
197197

198+
static bool fixDifferentiatorParentTagForUnflattenCase(
199+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
200+
198201
static bool fixFindShadowNodeByTagRaceCondition(
199202
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
200203

packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp

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<<b229243317998e64843f285f86af161c>>
7+
* @generated SignedSource<<eb31174e5f1e3f37503fe5c910a6b6c8>>
88
*/
99

1010
/**
@@ -246,6 +246,10 @@ bool ReactNativeFeatureFlags::enableVirtualViewDebugFeatures() {
246246
return getAccessor().enableVirtualViewDebugFeatures();
247247
}
248248

249+
bool ReactNativeFeatureFlags::fixDifferentiatorParentTagForUnflattenCase() {
250+
return getAccessor().fixDifferentiatorParentTagForUnflattenCase();
251+
}
252+
249253
bool ReactNativeFeatureFlags::fixFindShadowNodeByTagRaceCondition() {
250254
return getAccessor().fixFindShadowNodeByTagRaceCondition();
251255
}

packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h

Lines changed: 6 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<<86b3267ffa68e0f68280957aa54d5041>>
7+
* @generated SignedSource<<d9e55ee2af90103f57394e9683a0ac16>>
88
*/
99

1010
/**
@@ -314,6 +314,11 @@ class ReactNativeFeatureFlags {
314314
*/
315315
RN_EXPORT static bool enableVirtualViewDebugFeatures();
316316

317+
/**
318+
* Fix incorrect parentTag passed as parentTagForUpdate in the unflatten-unflatten branch of calculateShadowViewMutationsFlattener, which causes UPDATE mutations to reference a parent being created in the same batch.
319+
*/
320+
RN_EXPORT static bool fixDifferentiatorParentTagForUnflattenCase();
321+
317322
/**
318323
* Fix a use-after-free race condition in findShadowNodeByTag_DEPRECATED by using getCurrentRevision() instead of tryCommit() with a raw pointer.
319324
*/

0 commit comments

Comments
 (0)