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

[router]: include search parameters in the default Screen.getId() #26710

Merged
merged 12 commits into from
Feb 12, 2024

Conversation

marklawlor
Copy link
Contributor

@marklawlor marklawlor commented Jan 26, 2024

Why

push/navigate/replace don't work as expected with search parameters. React Navigation uses both the screen's name & ID to detect if the screen is within the stack. If the search parameters are not included in the ID then React Navigation will treat /test?a=true === /test?b=true

How

I've rewritten the createGetIdForRoute with annotations below. There are two main differences

  • It will now always return a string. If there are no search params and the route is not dynamic, its ID is the context key.
  • The ID will include search parameters for routes with no children (so _layout is the same).

Test Plan

I've adjusted the existing getId tests. All our testing tests still pass, but this is mostly due to lack of coverage.

Checklist

@expo-bot expo-bot added the bot: suggestions ExpoBot has some suggestions label Jan 26, 2024
* fall back to `key` based navigation. This is an issue for search parameters where are either
* part of the key or the id.
*/
return id || route.contextKey;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now always return an ID value. This prevents React Navigation from falling back to name & key based matching, where it may match on a correct key, but this screen may have had parameters.

expect(testRouter.canGoBack()).toBe(false);
});

it.skip('handles popToTop', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have popToTop on the router?. I'll add it in a new PR

@expo-bot expo-bot added bot: passed checks ExpoBot has nothing to complain about and removed bot: suggestions ExpoBot has some suggestions labels Jan 26, 2024
@kennethstarkrl
Copy link
Contributor

Related #26916

@marklawlor marklawlor force-pushed the marklawlor/router/getId-search-params branch from b0bee6c to 51dc0f9 Compare February 12, 2024 07:43
@marklawlor marklawlor merged commit a9ae283 into main Feb 12, 2024
9 checks passed
@marklawlor marklawlor deleted the marklawlor/router/getId-search-params branch February 12, 2024 09:01
marklawlor added a commit that referenced this pull request Feb 12, 2024
# 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 #26669

# Test Plan

The `navigation.test.ios.tsx` file is getting a bit messy, so I created
a new `push.test.ios.tsx` file. Over time I'm going to separate the rest
of the `navigation` tests into a `push`/`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

<!--
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: kennethstarkrl <kenneth@feednom.com>
@brentvatne brentvatne added the published Changes from the PR have been published to npm label Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: fingerprint compatible bot: passed checks ExpoBot has nothing to complain about published Changes from the PR have been published to npm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants