From 82d753fa4a1fa450ce41e1a9f3cb5ea251f615f8 Mon Sep 17 00:00:00 2001 From: ManasGuptaSprinklr <154529197+ManasGuptaSprinklr@users.noreply.github.com> Date: Fri, 19 Jun 2026 09:18:00 +0000 Subject: [PATCH] fix: add null checks for getViewState in SurfaceMountingManager --- .../fabric/mounting/SurfaceMountingManager.kt | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.kt index 3b5816a7e21c..ff07aee0c8e4 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.kt @@ -756,9 +756,14 @@ internal constructor( return } - val view = getViewState(reactTag).view + val viewState = getNullableViewState(reactTag) + val view = viewState?.view if (view == null) { - throw RetryableMountingLayerException("Unable to find viewState view for tag $reactTag") + ReactSoftExceptionLogger.logSoftException( + ReactSoftExceptionLogger.Categories.SURFACE_MOUNTING_MANAGER_MISSING_VIEWSTATE, + ReactNoCrashSoftException("Unable to find viewState for tag $reactTag for sendAccessibilityEvent"), + ) + return } view.sendAccessibilityEvent(eventType) @@ -1000,16 +1005,22 @@ internal constructor( return } - val viewState = getViewState(reactTag) - val view = viewState.view + val viewState = getNullableViewState(reactTag) + + val view = viewState?.view + if (view == null) { + ReactSoftExceptionLogger.logSoftException( + ReactSoftExceptionLogger.Categories.SURFACE_MOUNTING_MANAGER_MISSING_VIEWSTATE, + ReactNoCrashSoftException("Unable to find viewState for tag $reactTag for setJSResponder"), + ) + return + } + if (initialReactTag != reactTag && view is ViewParent) { // In this case, initialReactTag corresponds to a virtual/layout-only View, and we already // have a parent of that View in reactTag, so we can use it. jsResponderHandler.setJSResponder(initialReactTag, view as ViewParent) return - } else if (view == null) { - SoftAssertions.assertUnreachable("Cannot find view for tag [$reactTag].") - return } if (viewState.isRoot) { @@ -1118,12 +1129,6 @@ internal constructor( ) } - private fun getViewState(reactTag: Int): ViewState = - getNullableViewState(reactTag) - ?: throw RetryableMountingLayerException( - "Unable to find viewState for tag $reactTag. Surface stopped: $isStopped" - ) - private fun getNullableViewState(reactTag: Int): ViewState? = registryLock.read { tagToViewState[reactTag] }