Skip to content

Fix crash when dispatching cancel events to reparented views - #55273

Closed
fabriziocucci wants to merge 1 commit into
react:mainfrom
fabriziocucci:export-D90988373
Closed

Fix crash when dispatching cancel events to reparented views#55273
fabriziocucci wants to merge 1 commit into
react:mainfrom
fabriziocucci:export-D90988373

Conversation

@fabriziocucci

Copy link
Copy Markdown
Contributor

Summary:
Changelog: [Internal]

When FloatingView reparents its content to a SurfaceControlViewHost (for z-offset elevation), the child views are no longer descendants of the main React root view hierarchy. If a pointer cancel event is dispatched while the view is in this state, JSPointerDispatcher.getChildOffsetRelativeToRoot() calls offsetDescendantRectToMyCoords() which throws IllegalArgumentException: parameter must be a descendant of this view.

This fix makes getChildOffsetRelativeToRoot() return null when the view is not a descendant (catching only the specific "descendant" exception), and skips dispatching the cancel event in that case while still cleaning up internal pointer state.

This crash was occurring in IGVR when scrolling through story pogs with thumbstick input, as each pog uses FloatingView with elevation.

Reviewed By: javache

Differential Revision: D90988373

Summary:
Changelog: [Internal]

When `FloatingView` reparents its content to a `SurfaceControlViewHost` (for z-offset elevation), the child views are no longer descendants of the main React root view hierarchy. If a pointer cancel event is dispatched while the view is in this state, `JSPointerDispatcher.getChildOffsetRelativeToRoot()` calls `offsetDescendantRectToMyCoords()` which throws `IllegalArgumentException: parameter must be a descendant of this view`.

This fix makes `getChildOffsetRelativeToRoot()` return `null` when the view is not a descendant (catching only the specific "descendant" exception), and skips dispatching the cancel event in that case while still cleaning up internal pointer state.

This crash was occurring in IGVR when scrolling through story pogs with thumbstick input, as each pog uses `FloatingView` with elevation.

Reviewed By: javache

Differential Revision: D90988373
@meta-codesync

meta-codesync Bot commented Jan 22, 2026

Copy link
Copy Markdown

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

@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @fabriziocucci in 8544a68

When will my fix make it into a release? | How to file a pick request?

@meta-codesync

meta-codesync Bot commented Jan 22, 2026

Copy link
Copy Markdown

This pull request has been merged in 8544a68.

meta-codesync Bot pushed a commit that referenced this pull request Apr 2, 2026
Summary:
Guard `ReactViewGroup.addChildrenForAccessibility` against transient non-descendant races during accessibility traversal on Android.

This replaces direct `super.addChildrenForAccessibility(...)` calls with a small wrapper that:
- catches `IllegalArgumentException`
- only swallows the specific "descendant of this view" case
- rethrows all other `IllegalArgumentException`s

## Why
There are recurring crashes with stack traces ending in:
`ViewGroup.offsetRectBetweenParentAndChild` -> `offsetDescendantRectToMyCoords` -> `addChildrenForAccessibility` -> `IllegalArgumentException: parameter must be a descendant of this view`.

This can happen when accessibility is traversing children while views are being re-parented/removed.

Related reports:
- #32649
- #38925
- #7377
- kirillzyusko/react-native-keyboard-controller#961
- kirillzyusko/react-native-keyboard-controller#962
- dotnet/maui#32927

There is also precedent in RN for handling this class of non-descendant race defensively:
- #55273

## Scope
This is intentionally minimal and localized to accessibility child collection in `ReactViewGroup`. Behavior is unchanged in the non-racy path.

## Changelog:
[Android] [Fixed] - Guard `ReactViewGroup.addChildrenForAccessibility` against transient non-descendant accessibility traversal crashes.

Pull Request resolved: #56182

Test Plan: Validated in a downstream RN Android app on Android 16 with repeated sheet/modal open-close stress and active accessibility hierarchy traversal; crash reproduces before patch and no longer reproduces with this guard.

Reviewed By: jorge-cab

Differential Revision: D97861147

Pulled By: Abbondanzo

fbshipit-source-id: 15e624a94d5acd99777a7426787b52d8e85cdf8a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fb-exported Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants