-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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]: Refactor getRoutes
#26507
[router]: Refactor getRoutes
#26507
Conversation
730801f
to
a9130bd
Compare
Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
children: [], | ||
contextKey: './(app)/(index)/blog/abc.tsx', | ||
contextKey: './(app)/(index,about)/blog/abc.tsx', |
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.
contextKey is used as a unique identifier, it looks like it's possible for duplicates now?
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.
contextKey
is being used both as an ID and as a filename for various purposes.
The only place its used as an ID is the useContextKey()
hook for the navigators. I don't think this breaks their functionality, but we so don't have great test coverage for this 🤔
I'll add an id
attribute to RouteNode
which was the previous contextKey
value and update useContextKey
to return the ID value.
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.
Generally seems fine, depending on tests for a number of the advanced cases.
# Why Recreation of #25654. I'm splitting that PR into two PRs. 1. Move typed-routes logic 2. Refactor Expo Router so the code-base and typed routes shared the same definition file. I've also removed the custom directory-traversal logic and switched to using `getRoutes()` directly. This is in preparation of #26507 which fixes issue with the type generation. Close ENG-10759 # How **Previous** - Typed routes used its own directory walk logic to generate the paths for typed routes. - All logic lives in `@expo/cli` **new** - `@expo/cli`checks for the existence of `expo-router/build/typed-routes`. If so, it uses it instead of the current logic. - The updated functions call `getRoutes()` and traverse the `RouteNode` instead of the file-system. # Test Plan This PR only tests the integration between `getRoutes()` and the `expo-router.d.ts`. The next PR will add type tests that are in #25654 # 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>
Why
With the introduction of Platform Routes, the
getRoutes
function needs to be updated with additional rules/checks. This is a refactor before we start on that body of work.Current bugs
/page.tsx
&/page+api.tsx
will error as a duplicate route/folder/+html
is a valid routeCloses ENG-8005
Current DX issues
The existing error messages are very vague. I've taking this as an opportunity to improve them
Duplicate Route errors
The difference is now it tells you which two files are in conflict and why they are in conflict. It also leaves out redundant information like route priority.
Previous
New
Deprecated
_layout
formatThis format is now allowed.
Previous edit
This error is confusing as it can occur when your not trying to use `_layout`I'm not sure if I like this. It means we're kinda heading into everything is
page.tsx
territory.Previous
New
// new error message
"Layout ./_layout.js has invalid initialRouteName 'c'. Valid options are: 'a', 'b'"
// new error message if using group syntax
"Layout ./(a,b)/_layout.js has invalid initialRouteName 'd' for group '(b)'. Valid options are: 'c'"
type TreeNode = {
name: string;
children: TreeNode[];
parents: string[];
/** null when there is no file in a folder. */
node: FileNode | null;
};
type DirectoryNode = {
layout?: RouteNode[];
subdirectories: Map<string, DirectoryNode>;
files: Map<string, RouteNode[]>; // Each file is an array of RouteNode sorted by specificity
};