-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[router] fix router.push inside a group #26678
Conversation
import { act, renderRouter, screen } from '../testing-library'; | ||
import { Slot } from '../views/Navigator'; | ||
|
||
it('stacks should always push a new route', () => { |
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.
This test is a simplified version of #26669. There were two problems
- It targeted based upon name, so it always targeted
(group)/_layout
- Once that was fixed it didn't target correctly based upon different params, e.g
user/2
was targeting the<Stack />
insideuser/1/_layout
instead of(group)/_layout
Because of the incorrect target, Screens were being nested instead of pushed (hence why they switched instead of animated).
This test shows they are always being pushed
return keysA.every((key) => { | ||
const valueA = paramsA[key]; | ||
const valueB = paramsB[key]; | ||
return valueA === valueB || valueA?.toString?.() === valueB?.toString?.(); |
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.
return valueA === valueB || valueA?.toString?.() === valueB?.toString?.(); | |
return valueA == valueB |
If we're comparing numbers and strings, it would be cheaper to use ==
than to optionally convert to string.
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, assuming tests pass.
@marklawlor This fixes routing pushing to slug routes, however, there is still a bug for the same thing but with url query params. ie route/to/slug**?query=test** Looks like url queries aren't included in the params object. |
This is currently blocked by a number of small changes that I need to make. I'll update the description as a post new PRs |
f4fcb4a
to
9cd0b1a
Compare
f183146
to
45d2dd9
Compare
Co-authored-by: kennethstarkrl <kenneth@feednom.com>
45d2dd9
to
3adfd58
Compare
Why
Fix: #26669
Close: #26597
How
#26597 correctly identified that we need to deep compare the
params
. I cleaned up the logic and added unit tests which are a minimal reproduction of #26669Test Plan
The
navigation.test.ios.tsx
file is getting a bit messy, so I created a newpush.test.ios.tsx
file. Over time I'm going to separate the rest of thenavigation
tests into apush
/navigate
/replace
files.See comments for more information
Blocked by
#26710 - Screens with search parameters are being incorrectly handled
PR pending - Screens are not being hoisted correctly. This causes the
push
to behave incorrectly as the screen is not within the expected_layout
Checklist
npx expo prebuild
& EAS Build (eg: updated a module plugin).