Skip to content

[Android] popToTopOnBlur crashes with "index out of bounds for length 0" when nested native stack has 4+ screens #3818

Description

@IgorNovikov10

Description

When popToTopOnBlur: true is set on a Tab.Screen whose component is a
createNativeStackNavigator, switching away from that tab crashes on Android with
a fatal IndexOutOfBoundsException if the stack has 4 or more screens pushed.
The crash does NOT occur when the stack depth is 3 or fewer screens.

Expected behavior

popToTopOnBlur pops the nested stack to its first screen (as documented),
regardless of stack depth.

Actual behavior

Fatal crash on Android:

```
java.lang.IndexOutOfBoundsException: index 3 out of bounds for length 0
```

or

```
java.lang.IndexOutOfBoundsException: index 2 out of bounds for length 0
```

The index in the error corresponds to the number of screens minus one. With
≤3 screens, no crash occurs.

Screen_Recording_20260329_192534_Champagne.mp4

Root cause hypothesis

popToTopOnBlur internally dispatches StackActions.popToTop() during the tab
blur event. On Android, this triggers a native fragment transaction that attempts
to pop N-1 fragments simultaneously. The fragment manager's backstack array
appears to be emptied before the pop count is resolved, causing the OOB crash.

Workaround

The only crash-free workaround found is to avoid popToTopOnBlur and instead
manually call navigateToTab (a simple CommonActions.navigate tab switch,
no stack manipulation), accepting that the previous stack state is preserved
until the user next navigates to that tab.

Environment

  • react-native: 0.83.1
  • react-native-screens: 4.24.0
  • @react-navigation/bottom-tabs: 7.15.8
  • @react-navigation/native-stack: 7.14.9
  • Platform: Android only (iOS works correctly)
  • Architecture: Old Architecture (Bridge)

Steps to reproduce

  1. Set up a bottom tab navigator with a tab whose component is a native stack:

```jsx
<Tab.Screen
name="MyTab"
component={MyStackNavigator}
options={{ popToTopOnBlur: true }}
/>
```

  1. Push 4+ screens deep into that native stack:

```js
navigation.navigate('Screen1');
navigation.navigate('Screen2');
navigation.navigate('Screen3');
navigation.navigate('Screen4'); // <-- 4th screen
```

  1. Switch to any other tab programmatically via CommonActions.navigate:

```js
navigationRef.dispatch(
CommonActions.navigate({ name: 'OtherTab' })
);
```

  1. App crashes on Android immediately.

Snack or a link to a repository

1

Screens version

4.24.0

React Native version

0.83.1

Platforms

Android

JavaScript runtime

None

Workflow

None

Architecture

None

Build type

None

Device

None

Device model

Samsung Galaxy S25

Acknowledgements

Yes

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    close-when-staleThis issue is going to be closed when there is no activity for a whilemissing-infoThe user didn't precise the problem enoughmissing-reproThis issue need minimum repro scenarioplatform:androidIssue related to Android part of the library

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions