Commit e681736
Fix Android accessibility descendant race in ReactViewGroup (#56182)
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: 15e624a94d5acd99777a7426787b52d8e85cdf8a1 parent 8915341 commit e681736
2 files changed
Lines changed: 22 additions & 2 deletions
File tree
- packages/react-native/ReactAndroid/src/main/java/com/facebook/react
- bridge
- views/view
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| |||
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| 36 | + | |
| 37 | + | |
34 | 38 | | |
35 | 39 | | |
36 | 40 | | |
| |||
Lines changed: 18 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
997 | 997 | | |
998 | 998 | | |
999 | 999 | | |
1000 | | - | |
| 1000 | + | |
1001 | 1001 | | |
1002 | 1002 | | |
1003 | 1003 | | |
1004 | 1004 | | |
1005 | | - | |
| 1005 | + | |
1006 | 1006 | | |
1007 | 1007 | | |
1008 | 1008 | | |
| |||
1012 | 1012 | | |
1013 | 1013 | | |
1014 | 1014 | | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
1015 | 1021 | | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
1016 | 1032 | | |
1017 | 1033 | | |
1018 | 1034 | | |
| |||
0 commit comments