UIViewControllerHierarchyInconsistency crash when RCT_NEW_ARCH_ENABLED=1 on iOS
Description
When running a React Native app with New Architecture enabled (RCT_NEW_ARCH_ENABLED=1), the app crashes on iOS with the following error:
Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:<RNSViewController: 0x10737c1d0> should have parent view controller:(null) but actual parent is:<RNSScreen: 0x10988a400>'
This issue does not occur when running with Old Architecture (RCT_NEW_ARCH_ENABLED=0).
Crash Log (truncated):
*** First throw call stack: ( 0 CoreFoundation __exceptionPreprocess + 172 1 libobjc.A.dylib objc_exception_throw + 72 2 UIKitCore -[UIView(Hierarchy) _associatedViewControllerForwardsAppearanceCallbacks...] 3 UIKitCore -[UIView(Hierarchy) _willMoveToWindow:withAncestorView:] 4 UIKitCore -[UIView(Internal) _addSubview:positioned:relativeTo:] ... libc++abi: terminating due to uncaught exception of type NSException )
Steps to reproduce
Create a new React Native project or upgrade to RN 0.77.0.
Install the following dependencies:
"react-native": "0.77.0", "react-native-screens": "4.5.0", "react-native-gesture-handler": "2.22.1", "react-native-reanimated": "3.18.0", "expo": "52.0.0"
Enable New Architecture by setting RCT_NEW_ARCH_ENABLED=1.
Run the iOS app.
Observe crash during navigation transitions.
Snack or a link to a repository
None
Screens version
4.5.0
React Native version
0.77.0
Platforms
iOS
JavaScript runtime
None
Workflow
None
Architecture
None
Build type
Debug mode
Device
iOS simulator
Device model
iPhone 16 Pro
Acknowledgements
Yes
Hey! 👋
The issue doesn't seem to contain a minimal reproduction.
Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?
@kkafar @kligarski @mfazekas @ckknight @Minishlink Can any one help on this.
Hey @mpawar-ep-910!
We'll be happy to help, but:
- the report does not contain reproduction,
- the report does not contain steps to reproduce the issue,
- the stack trace is for some reason truncated and brings no suggestions where in the library code the crash happened,
- first thing to do is to update library version; 4.5.0 was released over 8 months ago and there is a chance the crash was mitigated in later version (small chances here, I do not recall this particular crash).
When upgrading please take into consideration the compatibility table and follow the upgrade helper.
We won't be able to help in any other way unless we are able to reproduce the issue on our end. Can you provide us with more information?
@kkafar There are no specific steps; once the app launches, it immediately throws this error.
running only yarn ios command only
I'm sorry, but we do not observe the error on our end.
Unless you provide us with information I've mentioned above, we won't be able to help much.
I get the same, it seems to only appear if using an expo application on iOS and pressing R on the console to reload the application. Once it reloads it seems to throw this error and cause a crash.
I'll see if I can create a minimal reproducible scenario to assist.
I'm currently reproducing on an iPhone 15 Pro
Thanks for the information @ghost1face! 🤞🏻 you manage to reproduce it!
Facing the same crash when launching the iOS app. "react-native": "0.82.1", "react-native-screens": "^4.18.0",