Skip to content

[Android] IllegalStateException in ScreenStackFragment.canNavigateBack: fragment added into a non-stack container #4429

Description

@nicksrandall

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    platform:androidIssue related to Android part of the libraryrepro-providedA reproduction with a snack or repo is provided

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions