0

React native 0.76.6 (old architecture)

React Navigation v7

My React Native app crashes on Android with java.lang.OutOfMemoryError, but works fine on iOS. Sentry logs reveal a breadcrumb loop like:

// Sentry Breadcrumbs
"message": "Navigation to Login", "data": { "from": "Login", "to": "Login" }
// Repeats hundreds of times before crash

First of all, I'd like to mention that I haven't been able to replicate the supposed crash nor have the users reported anything yet.

The crash happens shortly after the app renders LoginScreen. My navigation setup uses Zustand for auth state and React Navigation (Drawer). The initialRouteName depends on global state:

  // AppNavigator.js
initialRouteName={
  selectedUser?.id ? 'Home'
  : isAuthenticated ? 'UserSelection'
  : 'Login'
}

If not authenticated, only Login is rendered. After login, I call:

// LoginScreen.js
navigation.reset({ index: 0, routes: [{ name: 'UserSelection' }] });

My theory: a race condition between isAuthenticated state update and navigation re-evaluation is causing an infinite loop - the navigator keeps reloading Login, exhausting memory.

Here is  the stack trace, as provided by Sentry

2
  • 1
    You're describing stack overflow due to infinite recursion. Post the stack trace so we can see the loop and figure out why it's recursing. Commented Sep 20 at 4:18
  • @GabeSechan I edited the post to include the stack trace, as provided by Sentry. Personally, I can't find much use for it in this case, but maybe someone can. Commented Sep 20 at 10:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.