[router]: ensure navigation events are fired at correct target #27485
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why
Expo Router was incorrectly firing events with the incorrect navigator target. This would cause situations where the event was ignored or the state in correct.
The result of this was a sublty incorrect routing state that was
How
I rewrote
getNavigateAction
to get the action in a single pass. Previously we were getting the action, and then refining the action based up on the parent navigator.This approach could have worked, but the structure of the navigation action is, well, weird. This made converting an action into the targeted action error prone.
The new approach is to first identify the target, and then build the correct navigation action.
Test Plan
The fixed heirarachy (and incorrect back behaviour) can be demonstrated by this test. Now the routes are correctly pushing to the
<Stack />
inside the(group)
This incorrect back behaviour can be demonstrated by this test. Notice how some routes were previously not added to the history, causing the back behaviour to "skip" a route
Checklist
npx expo prebuild
& EAS Build (eg: updated a module plugin).