-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
🐛 BUG: injectRoute overwrites existing routes if entrypoint is already used #3602
Comments
CC @thepassle |
Thats interesting, we do have a check to see if there is a route collision: https://github.com/withastro/astro/blob/main/packages/astro/src/core/routing/manifest/create.ts#L327-L332 That should throw an error if there are route collisions. Could you try debugging that and seeing why it doesnt throw the error? |
That check detects if there is a collision in the If I have injectRoute({
pattern: '/ja/',
entryPoint: 'src/pages/index.astro',
}) then the collision check will compare |
Interesting@ This was not the intended use-case of the integration API. It was meant to be so that you could create routes using files outside of |
Closing as we're not going to change this behavior. Injected routes come last and override any routes that might also match. |
Hi everyone 👋 I'm currently making an Astro integration where my
@matthewp Not the problem, in my case the injects match different patterns, which work very well locally : archetypes.forEach((archetype) => {
// Inject a route for each archetype index
injectRoute({
pattern: `/${archetype.path}`,
entrypoint: getEntryPoint(archetype),
prerender: true,
})
})
archetypes.forEach((archetype) => {
// Inject a route for each archetype dynamic route
injectRoute({
pattern: `/${archetype.path}/[...slug]`,
entrypoint: getDynamicEntryPoint(archetype),
prerender: true,
})
}) The only explanation is that I use the same entrypoint several times, for two "archetypes" of the same type, to allow users to generate several blog collections for example. function getEntryPoint(archetype: Archetype): string {
switch (archetype.type) {
case "blog-content":
return "@goulvenclech/astropi/pages/blog.astro"
case "docs-content":
return "@goulvenclech/astropi/pages/docs-content.astro"
case "docs-openapi":
return "@goulvenclech/astropi/pages/docs-openapi.astro"
default:
return "@goulvenclech/astropi/pages/index.astro"
}
} I think this issue should be re-opened. Firstly because I don't see why the
|
Hi @goulvenclech, can you double-check whether you are on the latest version of Astro? There was a PR recently (#10248) that was supposed to fix the cache collision causing routes with the same entrypoints to misbehave. The example case there was fixed, if there is another or if there was a regression since then you can open a new issue with a reproduction :) |
Thanks @Fryuni for your response, but this is not a cache bug, rather in the prod build. I'm running on the latest Astro version I'm gonna create a new issue ! |
What version of
astro
are you using?v1.0.0-beta.46
Are you using an SSR adapter? If so, which one?
None
What package manager are you using?
yarn
What operating system are you using?
Windows (WSL2 w/ Ubuntu)
Describe the Bug
Calling
injectRoute
with anentrypoint
already used by an existing page insrc/pages
or by another call toinjectRoute
will cause the previous route to be overwritten. This happens regardless of the value ofpattern
, it does not matter if the pattern is static or dynamic. For simplicity, the minimal reproducible example uses a static pattern.From my brief investigation, this seems to be related to
collectPagesData
which iterates over all registered routes and builds a map ofentrypoint -> PageBuildData
. Since it assigns rather than merging, it causes prior validPageBuildData
to be lost.I'd be willing to file a PR but would first want to confirm that changing the result to an Array and having entries with duplicate
entrypoint
s is acceptable.Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-cwhwmd?file=astro.config.mjs
Participation
The text was updated successfully, but these errors were encountered: