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] Support platform extensions for _layout and routes #27408

Merged
merged 15 commits into from Apr 26, 2024

Conversation

marklawlor
Copy link
Contributor

@marklawlor marklawlor commented Mar 4, 2024

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

  • Used in getManifest()
  • Used in getBuildTimeServerManifestAsync ❌ - I'm not 100% sure on this one. Need to understand how to test this correctly

routes-manifest

  • Used in createRoutesManifest

router-store

  • Used in RouterStore

typed-routes

  • Used in getTypedRoutesDeclarationFile

There is also an getExactRoutes function, but this is only used for testing purposes.

**

Test Plan

Checklist

@expo-bot expo-bot added the bot: suggestions ExpoBot has some suggestions label Mar 4, 2024
@marklawlor marklawlor force-pushed the marklawlor/router/platform-routes branch from 6968551 to f3f7322 Compare March 4, 2024 02:07
@marklawlor marklawlor marked this pull request as ready for review March 4, 2024 02:54
@marklawlor

This comment was marked as outdated.

@expo-bot expo-bot added bot: passed checks ExpoBot has nothing to complain about and removed bot: suggestions ExpoBot has some suggestions labels Mar 6, 2024
@marklawlor marklawlor force-pushed the marklawlor/router/platform-routes branch from 53499e4 to 6abf431 Compare March 6, 2024 01:49
@marklawlor marklawlor force-pushed the marklawlor/router/platform-routes branch 2 times, most recently from acb9137 to dedd218 Compare March 20, 2024 22:45
@marklawlor marklawlor force-pushed the marklawlor/router/platform-routes branch from 077f3a1 to 9734cad Compare April 8, 2024 20:03
@marklawlor
Copy link
Contributor Author

Add flag to disable.
Merge into next SDK

@marklawlor marklawlor force-pushed the marklawlor/router/platform-routes branch from 6822c01 to 01da3f8 Compare April 22, 2024 08:37
@expo-bot expo-bot added bot: suggestions ExpoBot has some suggestions bot: passed checks ExpoBot has nothing to complain about and removed bot: passed checks ExpoBot has nothing to complain about bot: suggestions ExpoBot has some suggestions labels Apr 22, 2024
@marklawlor marklawlor force-pushed the marklawlor/router/platform-routes branch from ac5551a to 80f891a Compare April 25, 2024 20:04
@marklawlor marklawlor force-pushed the marklawlor/router/platform-routes branch from 80f891a to 924e498 Compare April 25, 2024 22:19
@marklawlor marklawlor merged commit c46e44c into main Apr 26, 2024
13 checks passed
@marklawlor marklawlor deleted the marklawlor/router/platform-routes branch April 26, 2024 00:51
@brentvatne brentvatne added the published Changes from the PR have been published to npm label Apr 26, 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