software-mansion / software-mansion/react-native-screens
[Android] IllegalStateException in ScreenStackFragment.canNavigateBack: fragment added into a non-stack container
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 3.7k
- Forks
- 714
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 71
Description
Description
We are seeing an intermittent production crash on Android 16 while React Native Screens updates a stack header configuration under Fabric:
java.lang.IllegalStateException: ScreenStackFragment added into a non-stack container
at com.swmansion.rnscreens.ScreenStackFragment.canNavigateBack(ScreenStackFragment.kt:503)
at com.swmansion.rnscreens.ScreenStackHeaderConfig.onUpdate(ScreenStackHeaderConfig.kt:282)
at com.swmansion.rnscreens.ScreenStackHeaderConfigViewManager.onAfterUpdateTransaction(ScreenStackHeaderConfigViewManager.kt:82)
at com.facebook.react.uimanager.ViewManager.updateProperties(ViewManager.java:104)
at com.facebook.react.fabric.mounting.SurfaceMountingManager.updateProps(SurfaceMountingManager.kt:682)
at com.facebook.react.fabric.mounting.mountitems.IntBufferBatchMountItem.execute(IntBufferBatchMountItem.kt:127)
The exception originates from the invariant inside ScreenStackFragment.canNavigateBack(). At the time of the header update, the fragment's container is apparently no longer a ScreenStack.
This is frequent in our current production release and occurs across multiple users. We have not found an application frame or an unsupported direct native call preceding the failure.
Steps to reproduce
We do not yet have a deterministic minimal reproduction. It occurs intermittently during normal Expo Router navigation in a release build, apparently while a screen header configuration is updated during a Fabric mount transaction.
Expected behavior
A header update during navigation should not crash when the fragment/container relationship is transiently changing. If the fragment is no longer attached to a ScreenStack, canNavigateBack() should handle that lifecycle state safely.
Actual behavior
ScreenStackFragment.canNavigateBack() throws IllegalStateException, terminating the Android app.
Environment
- React Native Screens: 4.26.2
- React Native: 0.86.0
- Expo: 57.0.8
- Expo Router: 57.0.8
- Platform: Android 16
- Architecture: Fabric / New Architecture
- Build type: Release
- Device: Real devices
Additional context
We searched the existing tracker for the exception text, canNavigateBack, and non-stack-container reports and did not find a matching issue. Issue #2989 is also an intermittent Android/Fabric fragment crash, but it has a different exception and stack (ViewGroup.dispatchAttachedToWindow), so this appears distinct.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with ScreenStackFragment.kt:503 and ScreenStackHeaderConfig.kt:282, then trace the Fabric update path shown in the stack to understand the transient container state. Validate the behavior during Expo Router navigation in an Android release build with Fabric; done means a header update no longer terminates the app when the fragment/container relationship is changing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin, react-native
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 45/100