Skip to content

Duplicate pathname rendering triggers misleading warning messages #17832

Description

@ariadne-depace

Astro Info

Astro                    v7.2.7
Node                     v24.15.0
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

Running a static build results in warnings like these:
[WARN] [build] Could not render /page2 from route /[slug] as it conflicts with higher priority route /[post].
The problem in this case was a duplicate in the slug route, two entries with the same pathname and was correctly detected. However, the second part of the message, which carries the important information about the original route that renders that path (the "winning route") is wrong because of a logic error.
This line

const matchedRoute = matchRoute(decodeURI(pathname), options.routesList);

finds the first route with a format that matches the pathname and assumes that this is the winning one. This is wrong, as multiple routes may match a pathname but a specific pathname may not be emitted from that route's getStaticPaths function.
Even if you assume that the same route template does not output the same pathname twice, the rule is still technically wrong in finding the correct winning route.
This problem can happen frequently when building from an headless cms with many templates corresponding to different content-types which may have overlapping routes, when is difficult to put guardrails at the cms level to avoid this. Retrieving the correct original route template, that usually correspondes to the content-type is very useful for finding the original content.
To reproduce see the stackblitz and just run npm run build. Keep in mind that the terminal emulator often truncates the warning.

What's the expected result?

In this case, the message should have produced an output like these:
[WARN] [build] Could not render /page2 from route /[slug] as it conflicts with with the same pathname from route /[slug].
Basically the message should output the correct route template that rendered the original page and blocked the rendering of the current pathname/route combination.
As a suggestion, I think this:

const builtPaths = new Set<string>();

should be turned into a Map keeping the builded pathname as the key and the original route template as the value, to be able to retrieve it when building the error.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-wkbrhntc?file=src%2Fpages%2F[slug].astro

Participation

  • I am willing to submit a pull request for this issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

- P3: minor bugAn edge case that only affects very specific usage (priority)pkg: astroRelated to the core `astro` package (scope)triage: fix verifiedReporter confirmed the triage bot fix works

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions