Skip to content

Duplicate slug property across MD files causes the page to be overwritten without warning. #14846

@chtx

Description

@chtx

Astro Info

Astro                    v5.16.0
Vite                     v6.4.1
Node                     v23.8.0
System                   Windows (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             @astrojs/mdx (v4.3.12)
                         @astrojs/sitemap (v3.6.0)

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

No response

Describe the Bug

Description:

When there are duplicate slug properties across two or more MD files, the routes will get overwritten without warning or error and only a single route will be created.

The issue is in the glob() loader. When we are populating the store, we don't check if the id (here the custom slug) is already defined in the store before adding the entry. So the entry is simply overridden, and the last one being added wins. (Credit to @ArmandPhilippot for identifying the root cause)

if (store.has(id)) {
  console.log("DUPLICATE!");
}

How to reproduce:

  1. Install the "blog" template with npm create
  2. Add duplicate slug property in two MD files. E.g.:

first-post.md:

---
slug: 'fp'
---

markdown-style-guide.md:

---
slug: 'fp'
---
  1. Go to /blog. The "First Post" disappeared from the list because it was overwritten.

What's the expected result?

An error or at least a warning that a route is being overwritten. Right now it happens silently.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-i1sleqxz?file=src%2Fcontent%2Fblog%2Fmarkdown-style-guide.md

Participation

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P2: nice to haveNot breaking anything but nice to have (priority)feat: content collectionsRelated to the Content Collections feature (scope)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions