fix(ios): guard against UIViewControllerHierarchyInconsistency in all navigation hosts#10316
fix(ios): guard against UIViewControllerHierarchyInconsistency in all navigation hosts#10316huhuanming wants to merge 6 commits intoxfrom
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
…igation Extend the UIHostingController skip guard to all reactAddControllerToClosestParent call sites in react-native-screens. The previous patch (decd5ee) only covered RNSScreenStack.mm, but the same crash occurs via RNSBottomTabsHostComponentView, RNSSplitViewHostComponentView, RNSStackHostComponentView, and RNSScreenContainer when SwiftUI re-parents UIHostingController during layout updates. RNSScreenContainer inherits reactAddControllerToClosestParent from UIView+React (React Native core) so it needs its own override with the guard. Fixes REACT-NATIVE-3YZ
d335b97 to
89bac76
Compare
Code Review SummaryReviewed Items
Review FindingsFinding 1: Finding 2: Trailing whitespace in Resolution✅ No changes needed — Patch is clean. The |
…3yz-ios-viewcontroller-resolve # Conflicts: # patches/react-native-screens+4.23.0.patch
|
Merge conflict resolved — kept both iOS UIHostingController skip logic and Android FragmentManager reentrant transaction guard in the patch file. |
e0a9fb4 to
025343e
Compare
Summary
RNSScreenStack.mmto allreactAddControllerToClosestParent:call sites inreact-native-screensRNSNavigationControllergets added as a child ofUIHostingController, which SwiftUI then re-parents during layout updates, causingUIViewControllerHierarchyInconsistencydecd5eeead) only coveredRNSScreenStack.mmbut missed three other files:RNSBottomTabsHostComponentView.mm,RNSSplitViewHostComponentView.mm, andRNSStackHostComponentView.mmRoot Cause
When using
react-native-bottom-tabs(SwiftUI TabView), the tab content is wrapped inUIHostingController. SwiftUI internally re-parentsUIHostingControllerinstances during layout updates. Ifreact-native-screensattaches a navigation controller as a child ofUIHostingController, the parent reference becomes stale after SwiftUI re-parents it, triggeringUIViewControllerHierarchyInconsistency.Changes
patches/react-native-screens+4.23.0.patch-- Added UIHostingController skip guard to:RNSBottomTabsHostComponentView.mm(most likely crash source -- bottom tabs host)RNSSplitViewHostComponentView.mm(split view host)RNSStackHostComponentView.mm(stack host)The guard checks if the candidate parent view controller's class name contains "UIHostingController" and, if so, continues walking up the view hierarchy to find a stable non-SwiftUI parent.
Test plan
Fixes REACT-NATIVE-3YZ