Skip to content

Guard against measuring detached views in SurfaceMountingManager.updateLayout#56377

Open
cortinico wants to merge 1 commit intofacebook:mainfrom
cortinico:export-D99770236
Open

Guard against measuring detached views in SurfaceMountingManager.updateLayout#56377
cortinico wants to merge 1 commit intofacebook:mainfrom
cortinico:export-D99770236

Conversation

@cortinico
Copy link
Copy Markdown
Contributor

Summary:

Summary:

Catch IllegalStateException from viewToUpdate.measure() in SurfaceMountingManager.updateLayout() instead of skipping the entire layout update. This fixes a crash where Jetpack Compose's onMeasure throws when a ComposeView is detached from the window hierarchy, while ensuring layout(), visibility, and parent requestLayout() still execute normally.

Root cause: RN Fabric dispatches layout updates via Choreographer. If a ComposeView was detached, its onMeasure attempts to access windowRecomposer, throwing IllegalStateException.

Previous approach (D99770236v1): Used isAttachedToWindow guard to skip the entire method. This caused an E2E test regression — views created during Fabric's batch mount could receive layout updates before being attached, leaving them with zero dimensions.

New approach: Wrap only the measure() call in a try-catch for IllegalStateException, logging via ReactSoftExceptionLogger. The layout() call and all other state updates proceed normally, preserving correct view dimensions for all views.

Related: T263517828 (original crash task), D97087668 (similar guard in updateProps)

Instructions about RACER Diffs:

Commandeer this diff (recommended) or land with accept2ship tag.

This diff was generated by Racer AI agent on behalf of William Khoe for T263534248. If the diff quality is poor, consider contacting the user to provide clearer instructions on the task.

  • If you are happy with the changes, commandeer it if minor edits are needed. (we encourage commandeer to get the diff credit)
  • If you are not happy with the changes, please comment on the diff with clear actions and send it back to the author. Racer will pick it up and re-generate.
  • If you really feel the Racer is not helping with this change (alas, some complex changes are hard for AI) feel free to abandon this diff.
  • For M10N reviewers: as you review AI-generated diffs, we ask you to give them the same priority as human-generated diffs, and take action in a timely manner by either accepting, rejecting, or resigning as a reviewer. For diffs that don't meet the quality bar (e.g. code doesn't compile, not readable or introduces functionality regressions), we ask that you use the following hashtags to provide clear signals to improve our tools - #monlowqualitydiff #monwrongreviewerdiff

Generated by RACER, powered by Confucius
Session, Trace

Reviewed By: cortinico

Differential Revision: D99770236

…teLayout

Summary:
## Summary:
Catch `IllegalStateException` from `viewToUpdate.measure()` in `SurfaceMountingManager.updateLayout()` instead of skipping the entire layout update. This fixes a crash where Jetpack Compose's `onMeasure` throws when a `ComposeView` is detached from the window hierarchy, while ensuring `layout()`, visibility, and parent `requestLayout()` still execute normally.

**Root cause:** RN Fabric dispatches layout updates via Choreographer. If a `ComposeView` was detached, its `onMeasure` attempts to access `windowRecomposer`, throwing `IllegalStateException`.

**Previous approach (D99770236v1):** Used `isAttachedToWindow` guard to skip the entire method. This caused an E2E test regression — views created during Fabric's batch mount could receive layout updates before being attached, leaving them with zero dimensions.

**New approach:** Wrap only the `measure()` call in a try-catch for `IllegalStateException`, logging via `ReactSoftExceptionLogger`. The `layout()` call and all other state updates proceed normally, preserving correct view dimensions for all views.

Related: T263517828 (original crash task), D97087668 (similar guard in `updateProps`)
---
## Instructions about RACER Diffs:
**Commandeer this diff (recommended) or land with accept2ship tag.**

**This diff was generated by Racer AI agent on behalf of [William Khoe](https://www.internalfb.com/profile/view/3409840) for T263534248. If the diff quality is poor, consider contacting the user to provide clearer instructions on the task.**

- If you are happy with the changes, commandeer it if minor edits are needed. (**we encourage commandeer to get the diff credit**)
- If you are not happy with the changes, please comment on the diff with clear actions and send it back to the author. Racer will pick it up and re-generate.
- If you really feel the Racer is not helping with this change (alas, some complex changes are hard for AI) feel free to abandon this diff.
- **For M10N reviewers:** as you review AI-generated diffs, we ask you to give them the same priority as human-generated diffs, and take action in a timely manner by either accepting, rejecting, or resigning as a reviewer. For diffs that don't meet the quality bar (e.g. code doesn't compile, not readable or introduces functionality regressions), we ask that you use the following hashtags to provide clear signals to improve our tools - `#monlowqualitydiff` `#monwrongreviewerdiff`
---
> Generated by [RACER](https://www.internalfb.com/wiki/RACER_(Risk-Aware_Code_Editing_and_Refactoring)/), powered by [Confucius](https://www.internalfb.com/wiki/Confucius/Analect/Shared_Analects/Confucius_Code_Assist_(CCA)/)
[Session](https://www.internalfb.com/confucius?session_id=634a2946-3236-11f1-9c44-99a80a63f54d&tab=Chat), [Trace](https://www.internalfb.com/confucius?session_id=634a2946-3236-11f1-9c44-99a80a63f54d&tab=Trace)

Reviewed By: cortinico

Differential Revision: D99770236
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 8, 2026
@facebook-github-tools facebook-github-tools bot added p: Facebook Partner: Facebook Partner labels Apr 8, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync bot commented Apr 8, 2026

@cortinico has exported this pull request. If you are a Meta employee, you can view the originating Diff in D99770236.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant