Skip to content

Commit df6ff66

Browse files
cortinicofacebook-github-bot
authored andcommitted
Fix IllegalStateException in SurfaceMountingManager.removeViewAt
Summary: Fix a crash in `SurfaceMountingManager.removeViewAt()` where an `IllegalStateException` is thrown when the parent view is not a `ViewGroup`. The Fabric differ can emit inconsistent remove instructions that reference a parent whose instantiated view is no longer a `ViewGroup` (e.g. after view recycling). Since a non-`ViewGroup` cannot hold child views, the removal is a semantic no-op. Replace the hard throw with `ReactSoftExceptionLogger.logSoftException` + early return, matching the defensive pattern already used by peer conditions in the same method (null `parentViewState`, child already removed, wrong index). Also fixes a "a a" typo in the error message. [Session trajectory link](https://www.internalfb.com/intern/devai/devmate/inspector/?id=6e4f3440-7815-4fc9-a981-f1603aea521b) Differential Revision: D115211130
1 parent 85a8181 commit df6ff66

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,13 @@ internal constructor(
427427
val parentView = parentViewState.view
428428
checkNotNull(parentView) { "Unable to find parentView for tag $parentTag" }
429429
if (parentView !is ViewGroup) {
430-
val message =
431-
"Unable to remove a view from a a non-ViewGroup ${parentView.javaClass.simpleName} when removing [$tag] from parent [$parentTag]"
432-
FLog.e(TAG, message)
433-
throw IllegalStateException(message)
430+
ReactSoftExceptionLogger.logSoftException(
431+
TAG,
432+
ReactNoCrashSoftException(
433+
"Unable to remove a view from a non-ViewGroup ${parentView.javaClass.simpleName} when removing [$tag] from parent [$parentTag]"
434+
),
435+
)
436+
return
434437
}
435438

436439
if (SHOW_CHANGED_VIEW_HIERARCHIES) {

0 commit comments

Comments
 (0)