Navigation state persists across app backgrounding
Why it matters
Mobile OSes aggressively kill backgrounded apps to reclaim memory. Without state persistence, a user who navigated three screens deep, switched to Maps for directions, and came back lands on a cold splash screen with their place lost — breaking the session and dumping any in-progress form input. This is especially punishing on iOS where low-memory terminations are silent, and it corrupts any analytics funnel that assumes continuous sessions.
Severity rationale
Medium because state loss is only visible after background kills but severely degrades the session-continuity experience.
Remediation
Persist navigation state to AsyncStorage on change and restore it on mount before rendering NavigationContainer. Put this in src/navigation/RootNavigator.tsx:
import AsyncStorage from '@react-native-async-storage/async-storage'
const [initialState, setInitialState] = useState()
const [isReady, setIsReady] = useState(false)
useEffect(() => {
AsyncStorage.getItem('NAV_STATE').then((s) => {
if (s) setInitialState(JSON.parse(s))
setIsReady(true)
})
}, [])
if (!isReady) return null
return (
<NavigationContainer
initialState={initialState}
onStateChange={(s) => AsyncStorage.setItem('NAV_STATE', JSON.stringify(s))}
>
<RootNavigator />
</NavigationContainer>
)
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Mobile Navigation & Deep Linking Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
Taxons
History
- 2026-04-18·v1.0.0·Initial import from mobile-navigation-linking·automated