Skip to content

Commit 54b9af1

Browse files
coadometa-codesync[bot]
authored andcommitted
Avoid expensive exception throw in SynchronousMountItem for stopped surfaces (#56969)
Summary: Pull Request resolved: #56969 When a `SynchronousMountItem` is dispatched for a reactTag whose surface has already been torn down, the `RetryableMountingLayerException ` is thrown in `storeSynchronousMountPropsOverride` and `updatePropsSynchronously`. The exception was immediately caught in the `SynchronousMountItem.execute`, making it a costly no-op. For each throw the stack trace is captured while holding the ART mutator lock in shared mode. On devices with high thread counts and deep Choreographer call stacks, this contributes to ANR during `doFrame`. This diff switches `storeSynchronousMountPropsOverride` and `updatePropsSynchronously` to use the nullable `getSurfaceManagerForView` variant, which returns null and silently no-ops when the surface is missing — the same end behavior as before, without the exception overhead. Changelog: [Internal] Reviewed By: zeyap Differential Revision: D106094737 fbshipit-source-id: df19657acbf6f66c2489d31e7c91c4a5c1e4f0fc
1 parent abcb782 commit 54b9af1

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ internal class MountingManager(
265265
return
266266
}
267267

268-
getSurfaceManagerForViewEnforced(reactTag).storeSynchronousMountPropsOverride(reactTag, props)
268+
getSurfaceManagerForView(reactTag)?.storeSynchronousMountPropsOverride(reactTag, props)
269269
}
270270

271271
@UiThread
@@ -275,7 +275,7 @@ internal class MountingManager(
275275
return
276276
}
277277

278-
getSurfaceManagerForViewEnforced(reactTag).updatePropsSynchronously(reactTag, props)
278+
getSurfaceManagerForView(reactTag)?.updatePropsSynchronously(reactTag, props)
279279
}
280280

281281
/**

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@ internal class SynchronousMountItem(private val reactTag: Int, private val props
2020
mountingManager.storeSynchronousMountPropsOverride(reactTag, props)
2121
mountingManager.updatePropsSynchronously(reactTag, props)
2222
} catch (ex: Exception) {
23-
// TODO T42943890: Fix animations in Fabric and remove this try/catch?
24-
// There might always be race conditions between surface teardown and
25-
// animations/other operations, so it may not be feasible to remove this.
26-
// Practically 100% of reported errors from this point are because the
27-
// surface has stopped by this point, but the MountItem was queued before
28-
// the surface was stopped. It's likely not feasible to prevent all such races.
23+
// The surface-stopped race condition (which was the primary source of exceptions here)
24+
// is now handled by null-safe lookups in MountingManager. This catch remains as a
25+
// safety net for other potential failures (e.g., view manager bugs, state
26+
// inconsistencies during prop updates).
2927
}
3028
}
3129

0 commit comments

Comments
 (0)