What's happening
When a user logs in for the first time in a fresh session, the app crashes with:
Cannot read property 'stale' of undefined
The error originates from StackRouter.js inside expo-router / react-navigation, because the navigation state becomes undefined mid-transition.
Root cause
In OidcAuthProvider, the isLoading condition is:
const isLoading = isInitializing &&
(isUserFetchSuccess || isUserFetchError || !isAuthenticated);
The problem is the timing right after a successful login:
isAuthenticated flips to true
isUserFetchSuccess and isUserFetchError are still false (the getUserInfo() fetch is in-flight)
- The condition evaluates to
false → provider returns null
- The entire child tree (including the navigation stack) unmounts
- Once
getUserInfo() resolves, isLoading becomes true again and the tree remounts with a fresh/empty navigation state
- The navigation stack receives
state = undefined during the remount → crash
Reproduction
- Use
OidcAuthProvider with a stack navigator (e.g. expo-router)
- Start the app fresh (no cached session)
- Log in — the crash occurs consistently on the login → authenticated transition
Fix
Simplifying the condition to:
const isLoading = isInitializing;
Once the initialization is complete and isAuthenticated is set, the provider should keep rendering its children regardless of whether the user info fetch has finished. The user info can load in the background without tearing down the navigation tree.
This is what we're using as a local patch in our project (react-native-oidc-auth-core@0.1.3) and it resolves the issue.
Environment
react-native-oidc-auth-core: 0.1.3
react-native-oidc-auth-expo: 0.1.3
expo-router: ~55.0.3
react-native: 0.83.2
What's happening
When a user logs in for the first time in a fresh session, the app crashes with:
The error originates from
StackRouter.jsinsideexpo-router/react-navigation, because the navigation state becomesundefinedmid-transition.Root cause
In
OidcAuthProvider, theisLoadingcondition is:The problem is the timing right after a successful login:
isAuthenticatedflips totrueisUserFetchSuccessandisUserFetchErrorare stillfalse(thegetUserInfo()fetch is in-flight)false→ provider returnsnullgetUserInfo()resolves,isLoadingbecomestrueagain and the tree remounts with a fresh/empty navigation statestate = undefinedduring the remount → crashReproduction
OidcAuthProviderwith a stack navigator (e.g.expo-router)Fix
Simplifying the condition to:
Once the initialization is complete and
isAuthenticatedis set, the provider should keep rendering its children regardless of whether the user info fetch has finished. The user info can load in the background without tearing down the navigation tree.This is what we're using as a local patch in our project (
react-native-oidc-auth-core@0.1.3) and it resolves the issue.Environment
react-native-oidc-auth-core: 0.1.3react-native-oidc-auth-expo: 0.1.3expo-router: ~55.0.3react-native: 0.83.2