Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[router] Support platform extensions for _layout and routes (#27408)
# Why Revised version #26047 Blocked by #27407 # How Rules: * API routes cannot have platform extensions * Layouts and routes can have extensions only if a non-extension version exists For example, you have have `/page.web.tsx` only if `/page.tsx` also exists. This makes platform extensions an additive change and won't break concepts like universal deep linking and typed routes API routes do not support platform extensions as they are independent of a platform. # Implementation `getRoutes` allows multiple files to be assigned to the same route, but all files were given the same specificity. This PR adds logic to calculate the specificity of a file and to select the most specific file. Specificity highest-to-lowest `2`: Platform extension matches platform `1`: `.native` platform extension `0`: No platform extensions `-1`: Invalid route If no platform is provided to `getRoutes` the current behaviour is retained and files with platform extensions will be ignored. # `getRoutes` checklist These are the locations we use `getRoutes` and whether they should use platform extensions or not. **[renderStaticContent](https://github.com/expo/expo/blob/269625f5b70a95656212ad14ca7f3e82b45b9f61/packages/expo-router/src/static/renderStaticContent.tsx#L19)** - Used in `getManifest()` ❌ - Used in `getBuildTimeServerManifestAsync` ❌ - I'm not 100% sure on this one. Need to understand how to test this correctly **[routes-manifest]( https://github.com/expo/expo/blob/269625f5b70a95656212ad14ca7f3e82b45b9f61/packages/expo-router/src/routes-manifest.ts#L4)** - Used in `createRoutesManifest` ❌ **[router-store](https://github.com/expo/expo/blob/269625f5b70a95656212ad14ca7f3e82b45b9f61/packages/expo-router/src/global-state/router-store.tsx#L27)** - Used in `RouterStore` ✅ **[typed-routes](https://github.com/expo/expo/blob/269625f5b70a95656212ad14ca7f3e82b45b9f61/packages/expo-router/src/typed-routes/generate.ts#L5)** - Used in `getTypedRoutesDeclarationFile` ❌ There is also an `getExactRoutes` function, but this is only used for testing purposes. ** # 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: Evan Bacon <bacon@expo.io> Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
- Loading branch information
1 parent
67ad439
commit c46e44c
Showing
37 changed files
with
650 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export const ctx = require.context( | ||
process.env.EXPO_ROUTER_APP_ROOT, | ||
true, | ||
/^(?:\.\/)(?!(?:(?:(?:.*\+api)|(?:\+html)))\.[tj]sx?$).*\.[tj]sx?$/, | ||
/^(?:\.\/)(?!(?:(?:(?:.*\+api)|(?:\+html)))\.[tj]sx?$).*(?:\.ios|\.web)\.[tj]sx?$/, | ||
process.env.EXPO_ROUTER_IMPORT_MODE | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export const ctx = require.context( | ||
process.env.EXPO_ROUTER_APP_ROOT, | ||
true, | ||
/^(?:\.\/)(?!(?:(?:(?:.*\+api)|(?:\+html)))\.[tj]sx?$).*\.[tj]sx?$/, | ||
/^(?:\.\/)(?!(?:(?:(?:.*\+api)|(?:\+html)))\.[tj]sx?$).*(?:\.android|\.web)?\.[tj]sx?$/, | ||
process.env.EXPO_ROUTER_IMPORT_MODE | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export const ctx = require.context( | ||
process.env.EXPO_ROUTER_APP_ROOT, | ||
true, | ||
/^(?:\.\/)(?!(?:(?:(?:.*\+api)|(?:\+html)))\.[tj]sx?$).*\.[tj]sx?$/, | ||
/^(?:\.\/)(?!(?:(?:(?:.*\+api)|(?:\+html)))\.[tj]sx?$).*(?:\.android|\.ios|\.native)?\.[tj]sx?$/, | ||
process.env.EXPO_ROUTER_IMPORT_MODE | ||
); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.