-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Updates the dev server to handle multiple routes matching the same URL #4087
Conversation
🦋 Changeset detectedLatest commit: 03a253e The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Likely related to #3809 as well, dev routing should prioritize injected routes above all |
…ro/astro into fix/dev-dynamic-routing-priority
@@ -159,6 +159,29 @@ function comparator(a: Item, b: Item) { | |||
return a.file < b.file ? -1 : 1; | |||
} | |||
|
|||
function injectedRouteToItem( |
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.
This is used to sort injected routes with the same comparer used for user-defined routes
@@ -4,3 +4,8 @@ import type { ManifestData, RouteData } from '../../@types/astro'; | |||
export function matchRoute(pathname: string, manifest: ManifestData): RouteData | undefined { | |||
return manifest.routes.find((route) => route.pattern.test(pathname)); | |||
} | |||
|
|||
/** Finds all matching routes from pathname */ | |||
export function matchAllRoutes(pathname: string, manifest: ManifestData): RouteData[] { |
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.
used by the dev server to find all potential routes for the requested URL
const filePath = new URL(`./${maybeRoute.component}`, config.root); | ||
const preloadedComponent = await preload({ astroConfig: config, filePath, viteServer }); | ||
const [, mod] = preloadedComponent; | ||
// attempt to get static paths |
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.
does this result in getStaticPaths being called more than once?
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.
It's still only called once. The getStaticPaths()
result is always cached even if the params don't match
Just noticed we have a test to make sure it's only called once but that test only covers build
. I just pushed up a test that checks that for dev
as well 👍
Closes #3809
Changes
dev server now finds all page templates that match the requested URL and checks each one in priority order
astro dev
astro build
injected routes are now sorted with a higher priority than all user-provided page routes
Testing
routing-priority
tests passDocs
N/A bug fix only