Skip to content

Commit 64002fb

Browse files
generatedunixname1074695667417611meta-codesync[bot]
authored andcommitted
Handle missing viewState gracefully in SurfaceMountingManager.addViewAt (#56389)
Summary: Pull Request resolved: #56389 Pull Request resolved: #56376 Changelog: [ReactAndroid][Fixed] - Prevented a crash in Fabric mounting by handling missing viewState in SurfaceMountingManager.addViewAt() (log + no-op instead of throwing). ## Problem `SurfaceMountingManager.addViewAt()` throws `RetryableMountingLayerException` when a view tag is not found in the `tagToViewState` map. This exception is **not handled** in the `IntBufferBatchMountItem` execution path — the retry logic in `MountItemDispatcher` only catches this for `DispatchCommandMountItem`. The exception propagates and crashes the app. **Crash**: `RetryableMountingLayerException: Unable to find viewState for tag X. Surface stopped: false` **Process**: `com.oculus.firsttimenux:login` **Impact**: 44,763 occurrences / 14,674 affected users in 30 days Logview link: [252c85116a7ab5c4ec93ef3c3373cf9d](https://www.internalfb.com/logview/system_vros_crashes/252c85116a7ab5c4ec93ef3c3373cf9d) ## Root Cause `addViewAt()` uses `getViewState()` which throws on missing tags, while other methods like `removeViewAt()`, `updateProps()`, `updateLayout()`, and `deleteView()` all use `getNullableViewState()` with graceful null handling (soft exception log + early return). This inconsistency means `addViewAt` is the only mount operation that crashes when encountering a timing-related missing view state. ## Fix Changed `addViewAt()` to use `getNullableViewState()` for both parent and child tag lookups, matching the established pattern used by `removeViewAt`, `updateProps`, `updateLayout`, and `deleteView`. On null, a soft exception is logged with the `SURFACE_MOUNTING_MANAGER_MISSING_VIEWSTATE` category and the operation returns early. Reviewed By: cortinico Differential Revision: D99760257 fbshipit-source-id: 3ee9baadfaf1ccb9094effe5bfc2bf9d14bb4ddb
1 parent 81c9968 commit 64002fb

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,15 +282,29 @@ internal constructor(
282282
return
283283
}
284284

285-
val parentViewState = getViewState(parentTag)
285+
val parentViewState = getNullableViewState(parentTag)
286+
if (parentViewState == null) {
287+
ReactSoftExceptionLogger.logSoftException(
288+
ReactSoftExceptionLogger.Categories.SURFACE_MOUNTING_MANAGER_MISSING_VIEWSTATE,
289+
ReactNoCrashSoftException("Unable to find viewState for tag: [$parentTag] for addViewAt"),
290+
)
291+
return
292+
}
286293
if (parentViewState.view !is ViewGroup) {
287294
val message =
288295
"Unable to add a view into a view that is not a ViewGroup. ParentTag: $parentTag - Tag: $tag - Index: $index"
289296
FLog.e(TAG, message)
290297
throw IllegalStateException(message)
291298
}
292299
val parentView = parentViewState.view as ViewGroup
293-
val viewState = getViewState(tag)
300+
val viewState = getNullableViewState(tag)
301+
if (viewState == null) {
302+
ReactSoftExceptionLogger.logSoftException(
303+
ReactSoftExceptionLogger.Categories.SURFACE_MOUNTING_MANAGER_MISSING_VIEWSTATE,
304+
ReactNoCrashSoftException("Unable to find viewState for tag: [$tag] for addViewAt"),
305+
)
306+
return
307+
}
294308
val view = viewState.view
295309
checkNotNull(view) { "Unable to find view for viewState $viewState and tag $tag" }
296310

0 commit comments

Comments
 (0)