From c00f109cf8210bbdafbe8ce14d1661c0fd51d3f2 Mon Sep 17 00:00:00 2001 From: Dharya-dev Date: Tue, 19 May 2026 01:16:57 +0530 Subject: [PATCH 1/2] fix(mdx-loader): skip asset transformation for directory links with dots When a Markdown link targets a local directory that has a dot in its name (e.g., `[link](../directory-with.dot/)`), path.extname() returns a truthy value (`.dot`), causing the transformLinks plugin to incorrectly treat it as a file asset. This results in a failed require() call and a broken build. This fix adds a directory check via fs.stat() after resolving the local path. If the path is a directory, the asset transformation is skipped and the link is left as-is. Closes #11940 --- .../__fixtures__/directory-with.dot/index.md | 4 ++++ .../transformLinks/__tests__/index.test.ts | 18 ++++++++++++++++++ .../src/remark/transformLinks/index.ts | 7 +++++++ 3 files changed, 29 insertions(+) create mode 100644 packages/docusaurus-mdx-loader/src/remark/transformLinks/__tests__/__fixtures__/directory-with.dot/index.md diff --git a/packages/docusaurus-mdx-loader/src/remark/transformLinks/__tests__/__fixtures__/directory-with.dot/index.md b/packages/docusaurus-mdx-loader/src/remark/transformLinks/__tests__/__fixtures__/directory-with.dot/index.md new file mode 100644 index 000000000000..4a8408ae2373 --- /dev/null +++ b/packages/docusaurus-mdx-loader/src/remark/transformLinks/__tests__/__fixtures__/directory-with.dot/index.md @@ -0,0 +1,4 @@ +# Placeholder + +This is a dummy file inside a directory with a dot in its name. +It exists to test that directory links with dots are not treated as file assets. diff --git a/packages/docusaurus-mdx-loader/src/remark/transformLinks/__tests__/index.test.ts b/packages/docusaurus-mdx-loader/src/remark/transformLinks/__tests__/index.test.ts index 29bcad267a10..f9a64d226909 100644 --- a/packages/docusaurus-mdx-loader/src/remark/transformLinks/__tests__/index.test.ts +++ b/packages/docusaurus-mdx-loader/src/remark/transformLinks/__tests__/index.test.ts @@ -267,4 +267,22 @@ describe('transformLinks plugin', () => { }); }); }); + + it('does not transform link to a directory with a dot in its name', async () => { + const result = await processContent( + `[link](../directory-with.dot/)`, + ); + expect(result).toMatchInlineSnapshot( + `"[link](../directory-with.dot/)"`, + ); + }); + + it('does not transform link to a directory with a dot (no trailing slash)', async () => { + const result = await processContent( + `[link](../directory-with.dot)`, + ); + expect(result).toMatchInlineSnapshot( + `"[link](../directory-with.dot)"`, + ); + }); }); diff --git a/packages/docusaurus-mdx-loader/src/remark/transformLinks/index.ts b/packages/docusaurus-mdx-loader/src/remark/transformLinks/index.ts index 192c1e9f8cee..19bde36fa76c 100644 --- a/packages/docusaurus-mdx-loader/src/remark/transformLinks/index.ts +++ b/packages/docusaurus-mdx-loader/src/remark/transformLinks/index.ts @@ -229,6 +229,13 @@ async function processLinkNode(target: Target, context: Context) { ); if (localFilePath) { + // Skip asset transformation for directories (e.g., "directory-with.dot/") + // A directory path with a dot can match hasAssetLikeExtension, but it + // should not be treated as a file asset — it's a valid link target. + const stats = await fs.stat(localFilePath); + if (stats.isDirectory()) { + return; + } await toAssetRequireNode(target, localFilePath, context); } else { // The @site alias is the only way to believe that the user wants an asset. From 9890260754d9d627919e9a06c365ca3ccbee946c Mon Sep 17 00:00:00 2001 From: Dharya-dev Date: Tue, 19 May 2026 01:51:47 +0530 Subject: [PATCH 2/2] chore: retrigger CLA check