react-navigation / react-navigation/react-navigation
goback throws error on popstate (nextjs)
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 24.5k
- Forks
- 5.1k
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 18
Description
Current Behavior
When I use @expo/next-adapter with react-navigation and its navigation container linking, "go back" functionality throws (even if I can actually go to the correct previous page).
`popstate` event triggered but `event.state` did not have `url` or `as` https://err.sh/zeit/next.js/popstate-state-empty
Uncaught (in promise) TypeError: Cannot read property 'indexOf' of undefined
at addBasePath (router.js:1)
at router.js:1
at new Promise (<anonymous>)
at Router.change (router.js:1)
at Router.replace (router.js:1)
at Router.onPopState (router.js:1)
Expected Behavior
I expect goBack to navigate back without throwing errors.
How to reproduce
init
npx create-react-native-app -t with-nextjs
add deps
yarn add @react-navigation/native react-native-gesture-handler react-native-reanimated react-native-screens react-native-safe-area-context @react-native-community/masked-view @react-navigation/stack next-images
install deps
yarn
amend next.config.js
const { withExpo } = require('@expo/next-adapter');
const withImages = require("next-images");
module.exports = withExpo(withImages({
projectRoot: __dirname,
}));
amend index.js
import 'react-native-gesture-handler';
import * as React from 'react';
import { Button, View, Text } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
function HomeScreen({navigation}) {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Home Screen</Text>
<Button
title="Go to Details"
onPress={() => navigation.navigate('Details')}
/>
</View>
);
}
function DetailsScreen({navigation}) {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Details Screen</Text>
<Button
title="Go back home"
onPress={() => navigation.goBack()}
/>
</View>
);
}
const Stack = createStackNavigator();
const linking = {
prefixes: [],
config: {
screens: {
Home: 'home',
Details: 'details',
}
},
};
function App() {
return (
<NavigationContainer linking={linking}>
<Stack.Navigator initialRouteName="Home">
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Details" component={DetailsScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}
export default App;
run
yarn next dev
go to details screen and then go back to home screen - check browser console for error
Your Environment
| software | version |
|---|---|
| iOS or Android | Web |
| @react-navigation/native | 5.6.1 |
| @react-navigation/stack | 5.6.2 |
| react-native | 0.62.2 |
| expo | 38.0.4 |
| node | 12.16.3 |
| npm or yarn | 6.14.4 |
Expo CLI 3.21.5 environment info:
System:
OS: macOS Mojave 10.14.6
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 12.16.3 - ~/.nvm/versions/node/v12.16.3/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.4 - ~/.nvm/versions/node/v12.16.3/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
IDEs:
Android Studio: 3.6 AI-192.7142.36.36.6392135
Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild
npmPackages:
expo: ~38.0.0 => 38.0.4
react: ~16.11.0 => 16.11.0
react-dom: ~16.11.0 => 16.11.0
react-native: https://github.com/expo/react-native/archive/sdk-38.0.0.tar.gz => 0.62.2
react-native-web: 0.11.7 => 0.11.7
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the commands and dependency versions given, then inspect the navigation setup in index.js and the Expo/Next configuration in next.config.js. Trace the popstate path shown in the error and verify that pressing goBack from Details returns to Home without a browser-console error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nextjs, react, react-native, typescript
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100