docusaurus icon indicating copy to clipboard operation
docusaurus copied to clipboard

Docs plugin - possible conflict between docs files with similar names

Open xt8288 opened this issue 7 months ago • 5 comments

Have you read the Contributing Guidelines on issues?

Description

Hello, currently the framework is functioning smoothly. However, we've encountered an issue. Once a Markdown document starts with a number, a default URL is generated. For example, if the document names are "8 - aaa - test" and "6 - aaa - hello", there are also differences in the slug within the document. After previewing, the system will recognize them as one document. Has anyone encountered a similar problem and know how to solve it?

Self-service

  • [ ] I'd be willing to address this documentation request myself.

xt8288 avatar Apr 29 '25 09:04 xt8288

Please create a https://docusaurus.new runnable repro using our bug report template.

slorber avatar May 02 '25 17:05 slorber

https://stackblitz.com/edit/github-hju2cjvr?file=docs%2Ftutorial-basics%2F7-aaa-display.md

Image Image Image

xt8288 avatar May 06 '25 02:05 xt8288

Thanks, I confirm something weird is happening

slorber avatar May 06 '25 08:05 slorber

Thank you very much for your prompt reply. If this issue is fixed or you have any solutions, please let me know again. Since the local files I have were set up a year ago and may not be the latest version, it will be convenient for me to update my local files. Thank you again.

xt8288 avatar May 06 '25 09:05 xt8288

So, the problem is that both documents within the same directory gets assigned the same id

The logic looks like this:

const baseID: string = frontMatter.id ?? unprefixedFileName;
const id = [computeDirNameIdPrefix(), baseID].filter(Boolean).join('/');

The number prefix is not taken into consideration when computing the document id from its file system location.

To prevent such unexpected conflicts, I will add an error message when this happens and recommend that users provide an explicitly distinct front matter ID.


Really curious though: what's the reason you want to use the same name for both files, and only change the number prefix? Do you have a good use case for this?

slorber avatar Jun 02 '25 16:06 slorber