-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
fix(router): fix router.replace() navigation across nested navigators #24457
Conversation
ENG-10061 [expo-router] The action 'REPLACE' with payload {"name":"SCREEN"} was not handled by any navigator.
This issue was automatically imported from GitHub: #24353Issue accepted by markSummary:
|
@EvanBacon Can you suggest more test scenarios that I should cover here? |
…to marklawlor/router/ENG-10061
Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good and tests are passing. Original implementation was a hack.
…#884) * fix(router): fix router.replace() navigation across nested navigators backport fix from expo/expo#24457 * drop stateOperations * Delete routing.test.node.ts
Hi @marklawlor do you know when it will be available? |
@janusqa This pr is merged and released in the latest version 2.0.7, but in my application replace() does not replace or clear web history and I can go back :( |
@devoren thanks will take it for a spin. |
…#24457) # Why Fix ENG-10061 Fix expo/router#793 Fix expo/router#858 Fix expo/router#832 The `linkTo` function has two issues. * It has trouble navigating to screens in different navigators with identical names * it cannot perform a replace navigation while in a nested navigator (it can only replace at the currently level). # How The original plan was to change `linkTo` to do navigation by deterministic keys, but React Navigation 7.0 is removing key based navigation, so we'll keep with screen names. This PR rewrites the `linkTo` function and simplifies the logic into two paths. **push** `linkTo` will fire a dispatch action on the root navigator with the desired state. **replace** We compare the current navigation state vs the desired state and find the lowest common navigator that can perform a replace action. This would be the `<Stack/>` or `<Tabs />` navigator that the two states share in common. The common navigator (it could be the root navigator if they have nothing in common!) is the source of the replace event # Test Plan Manually tested and wrote a new test. # Checklist <!-- Please check the appropriate items below if they apply to your diff. This is required for changes to Expo modules. --> - [ ] Documentation is up to date to reflect these changes (eg: https://docs.expo.dev and README.md). - [ ] Conforms with the [Documentation Writing Style Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md) - [ ] This diff will work correctly for `npx expo prebuild` & EAS Build (eg: updated a module plugin). --------- Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
# Why - fix regression in #24457 # How - clone objects to prevent circular references. # Test Plan - Added test that could repro the issue. --------- Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
@devoren something is wrong here. I open app land on a page. I click a button which uses replace to move to a screen that is not the initial screen in another adjacent stack. The screen has no back button. Back button was expected that i can click on it to go to initial screen of stack. if i click on the bottom tab to take me to the initial screen in that stack then the initial screen has a back button, although it should not since its the initial screen. Will try to do a repro repo and file a bug issue for it. Also still getting a large warning "The |
# Why Fix: #25981 # How To be honest, I'm not 100% sure why its broken in the current state. It fires a navigation events on the shared Stack with what seems like the correct params. But we also don't need to track the last common Stack/Tab lastCommonNavigator. Pre-#24457, we used to fire navigation events on the root navigator, so #24457 tried to not deviate from this behaviour by only changing the behaviour Stacks&Tabs doing replace actions. #24600 cleaned up the logic of #24457 and unified the logic for all navigation types, but still only tracked the last common Stack/Tabs. I don't know why this breaks Drawer, it might be an internal implementation detail, but we can simply fire the event on the last common navigator - no matter what type it is. # Test Plan Add a smoke test for `<Drawer />`. I don't believe it was being previously tested. # Checklist <!-- Please check the appropriate items below if they apply to your diff. This is required for changes to Expo modules. --> - [ ] Documentation is up to date to reflect these changes (eg: https://docs.expo.dev and README.md). - [ ] Conforms with the [Documentation Writing Style Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md) - [ ] This diff will work correctly for `npx expo prebuild` & EAS Build (eg: updated a module plugin). --------- Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
# Why Fix: expo#25981 # How To be honest, I'm not 100% sure why its broken in the current state. It fires a navigation events on the shared Stack with what seems like the correct params. But we also don't need to track the last common Stack/Tab lastCommonNavigator. Pre-expo#24457, we used to fire navigation events on the root navigator, so expo#24457 tried to not deviate from this behaviour by only changing the behaviour Stacks&Tabs doing replace actions. expo#24600 cleaned up the logic of expo#24457 and unified the logic for all navigation types, but still only tracked the last common Stack/Tabs. I don't know why this breaks Drawer, it might be an internal implementation detail, but we can simply fire the event on the last common navigator - no matter what type it is. # Test Plan Add a smoke test for `<Drawer />`. I don't believe it was being previously tested. # Checklist <!-- Please check the appropriate items below if they apply to your diff. This is required for changes to Expo modules. --> - [ ] Documentation is up to date to reflect these changes (eg: https://docs.expo.dev and README.md). - [ ] Conforms with the [Documentation Writing Style Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md) - [ ] This diff will work correctly for `npx expo prebuild` & EAS Build (eg: updated a module plugin). --------- Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
Why
Fix ENG-10061
Fix expo/router#793
Fix expo/router#858
Fix expo/router#832
The
linkTo
function has two issues.How
The original plan was to change
linkTo
to do navigation by deterministic keys, but React Navigation 7.0 is removing key based navigation, so we'll keep with screen names.This PR rewrites the
linkTo
function and simplifies the logic into two paths.push
linkTo
will fire a dispatch action on the root navigator with the desired state.replace
We compare the current navigation state vs the desired state and find the lowest common navigator that can perform a replace action. This would be the
<Stack/>
or<Tabs />
navigator that the two states share in common. The common navigator (it could be the root navigator if they have nothing in common!) is the source of the replace eventTest Plan
Manually tested and wrote a new test.
Checklist
npx expo prebuild
& EAS Build (eg: updated a module plugin).