Skip to content

expo-router: doesn't restore state when using browser back/forward buttons #31747

Closed
@kasrak

Description

@kasrak

Minimal reproducible example

npx create-expo-app@latest; npm run web

What platform(s) does this occur on?

Web

Where did you reproduce the issue?

on web

Summary

https://www.loom.com/share/feae2f6b331a4f3cb9951633b3f7cf70

This issue repros on web if you create the Expo starter project via npx create-expo-app@latest

Repro steps:

  1. Load the app in a web browser
  2. Click the "Explore" tab at the bottom
  3. Click the browser's back button
  4. Click the browser's forward button

Expected: you should be back on the Explore tab

Actual: you're still on the home page, and there's this error in the console:

The action 'RESET' with payload {"stale":false,"type":"stack","key":"stack-89f_vt6bznNwe8ZDmp0mR","index":0,"routeNames":["(tabs)","+not-found","_sitemap"],"routes":[{"name":"(tabs)","state":{"stale":false,"type":"tab","key":"tab-Ecfq_pT2uRroKfUj4Po-9","index":1,"routeNames":["index","explore"],"history":[{"type":"route","key":"index-dvBVUdqMOoqRmecNnOOhN"},{"type":"route","key":"explore-UpUnmnhhbnvqR2dlmlgQn"}],"routes":[{"name":"index","path":"/","key":"index-dvBVUdqMOoqRmecNnOOhN"},{"name":"explore","key":"explore-UpUnmnhhbnvqR2dlmlgQn"}]},"key":"(tabs)-qAmiwyZ8AwBcDAYrlGgYK"}]} was not handled by any navigator.

There is this issue from react-navigator which might have a clue on the fix: react-navigation/react-navigation#9128

Someone in that thread said:

I was experiencing the same issue hitting back to the initial screen. My fix was to stop setting initialState on web as described in https://reactnavigation.org/docs/navigation-container/#initialstate

Environment

expo-env-info 1.2.0 environment info:
    System:
      OS: macOS 14.6.1
      Shell: 5.9 - /bin/zsh
    Binaries:
      Node: 20.10.0 - ~/.local/bin/node
      npm: 9.6.7 - ~/.nvm/versions/node/v18.17.1/bin/npm
      Watchman: 2024.05.06.00 - /opt/homebrew/bin/watchman
    Managers:
      CocoaPods: 1.15.2 - /usr/local/bin/pod
    SDKs:
      iOS SDK:
        Platforms: DriverKit 23.5, iOS 17.5, macOS 14.5, tvOS 17.5, visionOS 1.2, watchOS 10.5
    IDEs:
      Android Studio: 2024.1 AI-241.18034.62.2411.12071903
      Xcode: 15.4/15F31d - /usr/bin/xcodebuild
    npmPackages:
      expo: ~51.0.28 => 51.0.34
      expo-router: ~3.5.23 => 3.5.23
      react: 18.2.0 => 18.2.0
      react-dom: 18.2.0 => 18.2.0
      react-native: 0.74.5 => 0.74.5
      react-native-web: ~0.19.10 => 0.19.12
    Expo Workflow: managed

Expo Doctor Diagnostics

✔ Check Expo config for common issues
✔ Check package.json for common issues
✔ Check native tooling versions
✔ Check if the project meets version requirements for submission to app stores
✔ Check dependencies for packages that should not be installed directly
✔ Check for common project setup issues
✔ Check for app config fields that may not be synced in a non-CNG project
✔ Check npm/ yarn versions
✔ Check for issues with metro config
✔ Check for legacy global CLI installed locally
✔ Check that native modules do not use incompatible support packages
✔ Check Expo config (app.json/ app.config.js) schema
✔ Check that packages match versions required by installed Expo SDK
✔ Check that native modules use compatible support package versions for installed Expo SDK

Didn't find any issues with the project!

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions