Skip to content

Commit 82d753f

Browse files
fix: add null checks for getViewState in SurfaceMountingManager
1 parent 57ce6bc commit 82d753f

1 file changed

Lines changed: 18 additions & 13 deletions

File tree

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

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -756,9 +756,14 @@ internal constructor(
756756
return
757757
}
758758

759-
val view = getViewState(reactTag).view
759+
val viewState = getNullableViewState(reactTag)
760+
val view = viewState?.view
760761
if (view == null) {
761-
throw RetryableMountingLayerException("Unable to find viewState view for tag $reactTag")
762+
ReactSoftExceptionLogger.logSoftException(
763+
ReactSoftExceptionLogger.Categories.SURFACE_MOUNTING_MANAGER_MISSING_VIEWSTATE,
764+
ReactNoCrashSoftException("Unable to find viewState for tag $reactTag for sendAccessibilityEvent"),
765+
)
766+
return
762767
}
763768

764769
view.sendAccessibilityEvent(eventType)
@@ -1000,16 +1005,22 @@ internal constructor(
10001005
return
10011006
}
10021007

1003-
val viewState = getViewState(reactTag)
1004-
val view = viewState.view
1008+
val viewState = getNullableViewState(reactTag)
1009+
1010+
val view = viewState?.view
1011+
if (view == null) {
1012+
ReactSoftExceptionLogger.logSoftException(
1013+
ReactSoftExceptionLogger.Categories.SURFACE_MOUNTING_MANAGER_MISSING_VIEWSTATE,
1014+
ReactNoCrashSoftException("Unable to find viewState for tag $reactTag for setJSResponder"),
1015+
)
1016+
return
1017+
}
1018+
10051019
if (initialReactTag != reactTag && view is ViewParent) {
10061020
// In this case, initialReactTag corresponds to a virtual/layout-only View, and we already
10071021
// have a parent of that View in reactTag, so we can use it.
10081022
jsResponderHandler.setJSResponder(initialReactTag, view as ViewParent)
10091023
return
1010-
} else if (view == null) {
1011-
SoftAssertions.assertUnreachable("Cannot find view for tag [$reactTag].")
1012-
return
10131024
}
10141025

10151026
if (viewState.isRoot) {
@@ -1118,12 +1129,6 @@ internal constructor(
11181129
)
11191130
}
11201131

1121-
private fun getViewState(reactTag: Int): ViewState =
1122-
getNullableViewState(reactTag)
1123-
?: throw RetryableMountingLayerException(
1124-
"Unable to find viewState for tag $reactTag. Surface stopped: $isStopped"
1125-
)
1126-
11271132
private fun getNullableViewState(reactTag: Int): ViewState? = registryLock.read {
11281133
tagToViewState[reactTag]
11291134
}

0 commit comments

Comments
 (0)