Guard against measuring detached views in SurfaceMountingManager.updateLayout#56377
Open
cortinico wants to merge 1 commit intofacebook:mainfrom
Open
Guard against measuring detached views in SurfaceMountingManager.updateLayout#56377cortinico wants to merge 1 commit intofacebook:mainfrom
cortinico wants to merge 1 commit intofacebook:mainfrom
Conversation
…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
|
@cortinico has exported this pull request. If you are a Meta employee, you can view the originating Diff in D99770236. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Summary:
Catch
IllegalStateExceptionfromviewToUpdate.measure()inSurfaceMountingManager.updateLayout()instead of skipping the entire layout update. This fixes a crash where Jetpack Compose'sonMeasurethrows when aComposeViewis detached from the window hierarchy, while ensuringlayout(), visibility, and parentrequestLayout()still execute normally.Root cause: RN Fabric dispatches layout updates via Choreographer. If a
ComposeViewwas detached, itsonMeasureattempts to accesswindowRecomposer, throwingIllegalStateException.Previous approach (D99770236v1): Used
isAttachedToWindowguard 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 forIllegalStateException, logging viaReactSoftExceptionLogger. Thelayout()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.
#monlowqualitydiff#monwrongreviewerdiffReviewed By: cortinico
Differential Revision: D99770236