Skip to content

Commit

Permalink
[router]: change Href to not be generic / use expo-router package for…
Browse files Browse the repository at this point in the history
… tests (#27690)

# 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.

2. 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.

3. 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`.

4. 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

<!--
How did you build this feature or fix this bug and why?
-->

# Test Plan

<!--
Please describe how you tested this change and how a reviewer could
reproduce your test, especially if this PR does not include automated
tests! If possible, please also provide terminal output and/or
screenshots demonstrating your test/reproduction.
-->

# 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>
  • Loading branch information
marklawlor and expo-bot committed Mar 26, 2024
1 parent 62b3fbe commit 1e5f916
Show file tree
Hide file tree
Showing 29 changed files with 636 additions and 390 deletions.
2 changes: 1 addition & 1 deletion apps/sandbox/package.json
Expand Up @@ -11,7 +11,7 @@
"expo": "~51.0.0-unreleased",
"expo-router": "^3.0.0",
"react": "18.2.0",
"react-native": "0.74.0-rc.3"
"react-native": "0.74.0-rc.4"
},
"devDependencies": {
"babel-preset-expo": "~10.0.0"
Expand Down
1 change: 1 addition & 0 deletions packages/@expo/cli/CHANGELOG.md
Expand Up @@ -25,6 +25,7 @@
- Prevent run commands from hanging when the process completes. ([#26960](https://github.com/expo/expo/pull/26960) by [@EvanBacon](https://github.com/EvanBacon))
- Keep typed routes in-sync with current Expo Router version ([#26578](https://github.com/expo/expo/pull/26578) by [@marklawlor](https://github.com/marklawlor))
- Fix development codesigning certificate validity checks. ([#27361](https://github.com/expo/expo/pull/27361) by [@wschurman](https://github.com/wschurman))
- Included groups in Expo Router typed routes generation ([#27690](https://github.com/expo/expo/pull/27690) by [@marklawlor](https://github.com/marklawlor))

### 💡 Others

Expand Down
8 changes: 8 additions & 0 deletions packages/@expo/cli/jest.config.js
Expand Up @@ -14,5 +14,13 @@ module.exports = {
setupFiles: ['<rootDir>/e2e/setup.ts'],
clearMocks: true,
},
{
displayName: require('./package').name + '-types',
runner: 'jest-runner-tsd',
testRegex: '/__typetests__/.*(test|spec)\\.[jt]sx?$',
rootDir: path.resolve(__dirname),
roots,
globalSetup: '<rootDir>/src/start/server/type-generation/__typetests__/generateFixtures.ts',
},
],
};

0 comments on commit 1e5f916

Please sign in to comment.