Commit 64002fb
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: 3ee9baadfaf1ccb9094effe5bfc2bf9d14bb4ddb1 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
Lines changed: 16 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
285 | | - | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
286 | 293 | | |
287 | 294 | | |
288 | 295 | | |
289 | 296 | | |
290 | 297 | | |
291 | 298 | | |
292 | 299 | | |
293 | | - | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
294 | 308 | | |
295 | 309 | | |
296 | 310 | | |
| |||
0 commit comments