callstack / callstack/react-native-pager-view
[iOS] Stack overflow in _UIHostingView._hitTest with keyboard open on a page (8.0.2 and 9.0.4, New Architecture)
- Dominant language
- TypeScript
- Stars
- 3.4k
- Forks
- 476
- Avg merge
- 10d 21h
- Merged PRs (30d)
- 2
Description
## Summary
On iOS the app crashes with `EXC_BAD_ACCESS` / **stack overflow** inside `_UIHostingView._hitTest` while a page of `PagerView` has the software keyboard open (or has just dismissed it). The main thread shows ~70 consecutive `_UIHostingView._hitTest` frames (the trace is trimmed to 100 frames, so the real depth is larger) before it reaches the React Native hit-test path and runs out of stack.
It happens with **8.0.2** and with **9.0.4** (same stack), so none of the 8.0.3–9.0.4 changes (page wrapper as `UIViewControllerRepresentable`, `ignoresSafeArea`, hosting-controller reparenting in 9.0.2, `setPage` fix in 9.0.4) address it. 6.x (UIKit `UIPageViewController`) never crashed here.
Over the last 30 days: **27 crashes from 17 distinct users**, roughly every fourth user who reached that page. Users relaunch and crash again on the same page (up to 3 times in 3 minutes). Not reproducible in the simulator so far, only on devices.
## Environment
- react-native-pager-view **9.0.4** (also 8.0.2), Expo SDK 57, React Native **0.86.2**, React 19.2.3, **New Architecture (Fabric) enabled**, Hermes
- react-native-gesture-handler 2.32.x (buttons come from `pressto`'s `PressableScale`), react-native-keyboard-controller 1.21.9, react-native-screens 4.26, react-native-reanimated 4.5.1, react-native-safe-area-context 5.7
- iOS deployment target 16.4; crashes seen on iOS 26.1 – 26.6.1 (24 events) and iOS 18.7.7 / 18.7.8 (3 events)
- Devices: iPhone 14 Pro … iPhone 18 (iPhone14,2, 15,2, 15,3, 16,1, 16,2, 17,2, 17,3, 18,1, 18,2), iPad15,3 and iPad15,7 running the iPhone build
- App Store builds, production, breadcrumbs show `RNSScreen` → `UIHostingController` → `IntrospectionAnchorPlatformViewController` / `IntrospectionPlatformViewController`
## Setup that crashes
- `PagerView` with `scrollEnabled={false}` (pages are switched only via `ref.setPage`), 14 pages, all mounted (onboarding flow inside a `react-native-screens` native stack).
- One page contains a `TextInput` with `autoFocus` inside `KeyboardAwareScrollView` from react-native-keyboard-controller, plus a few RNGH-backed buttons (`pressto` → `RNGestureHandlerButton`).
- Sequence from breadcrumbs: page appears → keyboard shows (`UIKeyboardDidShowNotification`) → user types → taps a button → keyboard hides → taps the primary button → crash ~2 s later. Other events crash while the keyboard is still up.
## Crash (thread 0, from Sentry, oldest frame first)
```
_UIHostingView._hitTest ← repeated ~70 times (trimmed)
…
_UIHostingView._hitTest
ViewResponder.hitTest
ViewResponder.hitTest
MultiViewResponder.containsGlobalPoints
UIViewResponder.containsGlobalPoints
PlatformViewResponderBase.containsGlobalPoints
UIViewResponder.platformViewHitTest
-[UIView(Geometry) hitTest:withEvent:]
-[__NSSingleObjectArrayI enumerateObjectsWithOptions:usingBlock:]
__38-[UIView hitTest:withEvent:]_block_invoke
-[UIView(Geometry) _hitTest:withEvent:windowServerHitTestWindow:]
-[UIView(Geometry) hitTest:withEvent:]
-[__NSSingleObjectArrayI enumerateObjectsWithOptions:usingBlock:]
__38-[UIView hitTest:withEvent:]_block_invoke
-[UIView(Geometry) _hitTest:withEvent:windowServerHitTestWindow:]
-[RCTViewComponentView hitTest:withEvent:]
-[RCTViewComponentView betterHitTest:withEvent:]
-[RCTViewComponentView hitTest:withEvent:]
-[RCTViewComponentView betterHitTest:withEvent:]
-[RNGestureHandlerButtonComponentView hitTest:withEvent:] (RNGestureHandlerButtonComponentView.mm:270)
-[RNGestureHandlerButton hitTest:withEvent:] (RNGestureHandlerButton.mm:121)
-[RNGestureHandlerButton shouldHandleTouch:] (RNGestureHandlerButton.mm:75)
+[NSPredicate predicateWithFormat:]
+[NSPredicate predicateWithFormat:arguments:]
_qfqp2_performParsing
_qfqp2lex
strdup ← EXC_BAD_ACCESS, "Stack overflow in (null)"
```
Sentry title: `EXC_BAD_ACCESS: isEnabled > Stack overflow in (null)`, mechanism `mach`, `handled: no`. Older 8.0.2 events (same stack) were symbolicated to `facebook::react::concreteComponentDescriptorConstructor` as culprit, which is just where the stack ran out.
## What we tried
- 8.0.2 → 9.0.4: no change.
- Replacing `PagerView` with a plain `ScrollView`-based pager (`pagingEnabled`, `scrollEnabled={false}`, `scrollTo`) removes the crash entirely, which points at the SwiftUI hosting layer rather than at our page content.
## Question
Is the SwiftUI `TabView`/hosting-view hit-test recursion with the keyboard open a known issue for v8/v9? Happy to provide full Sentry events (all threads) or test a build with extra logging on the affected devices.
Contributor guide
Research direction
Start by reproducing the provided PagerView and keyboard sequence on an affected physical iOS device, then inspect the Sentry hit-test trace. Compare the SwiftUI hosting path with the plain ScrollView-based pager and review RNGestureHandlerButton.mm at lines 75, 121, and 270. Done means establishing whether the v8/v9 hosting layer causes the recursion and documenting a tested fix or mitigation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ios, react-native, swift
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100