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]: change Href to not be generic / use expo-router package for tests #27690

Merged
merged 7 commits into from Mar 26, 2024

Conversation

marklawlor
Copy link
Contributor

Why

There PR is multiple fixes for typed routes

  1. Generate the test fixtures using the same typed-route utility functions exported by Expo Router

Expo Router now provides the utility functions to generate the .d.ts file used for typed routes. This PR changes the @expo/cli tests to generate the fixture file using these functions.

  1. Change Href<T> to Href

I've personally had some issues with using custom components wrapped in fowardRef that use Href for a prop. forwardRef doesn't work well with generic components, so I've refactored the types so Href is no longer generic.

Not only does this fix this issue, it improves the editor autocomplete when inferring the Href value.

  1. Enable /(groups)/ in typed routes.

Technically they were always allowed, but partial routes are allowed. For example you can do /(group1)/(group2)/page or simply /(group1)/page or even just /page.

  1. Added a new set of tests to ensure that Href can be assigned to as expected.

With the changes to Href I've added new set to tests to ensure users can assign values to Href as expected.

How

Test Plan

Checklist

@@ -1,46 +1,38 @@
import { getTypedRoutesDeclarationFile } from 'expo-router/build/typed-routes/generate';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@EvanBacon I think this will break with your incoming changes. Please let me know what I should change it to

@expo-bot expo-bot added the bot: suggestions ExpoBot has some suggestions label Mar 15, 2024
dynamicRoutes: string[];
dynamicRouteTemplates: string[];
};
function getMockContext(context: string[]) {
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 need a real context here. The helpers inside Expo Router are not publicly exposed, and trying to access them is a commonjs/esm hassle.

marklawlor and others added 5 commits March 21, 2024 05:55
Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
@marklawlor marklawlor force-pushed the marklawlor/typed-routes/groups branch from 3fb5cd3 to f77cd3b Compare March 20, 2024 19:56
@marklawlor marklawlor merged commit 1e5f916 into main Mar 26, 2024
11 checks passed
@marklawlor marklawlor deleted the marklawlor/typed-routes/groups branch March 26, 2024 05:10
@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

4 participants