Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Navigation dispatches that include a replace break browser back #10992

Open
2 of 11 tasks
Jackman3005 opened this issue Nov 10, 2022 · 2 comments
Open
2 of 11 tasks

Comments

@Jackman3005
Copy link

Jackman3005 commented Nov 10, 2022

Current behavior

When dispatching multiple navigation actions at a time (especially when one is a replace) the browser back functionality is broken:

navigation.dispatch(
  StackActions.replace("Screen2")
);
navigation.push("Screen3");

Going from Screen 1 to Screen 3 by replacing screen 1 and adding screen 2 behind screen 3 results in the correct state at the end where there are two routes ['screen 2', 'screen 3']. Using navigation.pop() works as expected and it would pop up to screen 2. The issue is when hitting the browser back from screen 3 I am taken back to screen 1.

Expected behavior

Browser back should perform the same as navigation.pop().

I think the issue lies in these lines of native/src/useLinking.tsx. The delta logic seems to only be accurate when one change is being processed at a time.

Maybe this logic needs to be executed for each state change regardless of render cycle?

Not sure tbh how it all works together.

Reproduction

https://snack.expo.dev/@jcoy/react-navigation-multiple-dispatch-browser-history-bug

Platform

  • Android
  • iOS
  • Web
  • Windows
  • MacOS

Packages

  • @react-navigation/​bottom-tabs
  • @react-navigation/​drawer
  • @react-navigation/​material-bottom-tabs
  • @react-navigation/​material-top-tabs
  • @react-navigation/​stack
  • @react-navigation/​native-stack

Environment

package version
@react-navigation/native 6.0.4
@react-navigation/stack 6.2.1
react-native-safe-area-context 4.2.4
react-native-screens 3.11.1
react-native-gesture-handler 2.2.1
react-native-reanimated 2.8.0
react-native 0.68.2
expo 45.0.0
node 16
npm or yarn yarn
@github-actions
Copy link

The versions mentioned in the issue for the following packages differ from the latest versions on npm:

  • @react-navigation/native (found: 6.0.4, latest: 6.0.13)
  • @react-navigation/stack (found: 6.2.1, latest: 6.3.4)

Can you verify that the issue still exists after upgrading to the latest versions of these packages?

@Jackman3005
Copy link
Author

For anyone who finds this because they are experiencing the same issue. I was able to resolve it by delaying firing my second action.

navigation.dispatch(StackActions.replace("Screen2"));
setTimeout(() => {
  navigation.push("Screen3") 
}, 0);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant