Skip to content

fix: preserve asset URLs when trailingSlash is enabled - #12323

Open
Sudemc wants to merge 2 commits into
facebook:mainfrom
Sudemc:fix/asset-link-trailing-slash-ready
Open

fix: preserve asset URLs when trailingSlash is enabled#12323
Sudemc wants to merge 2 commits into
facebook:mainfrom
Sudemc:fix/asset-link-trailing-slash-ready

Conversation

@Sudemc

@Sudemc Sudemc commented Jul 28, 2026

Copy link
Copy Markdown

Pre-flight checklist

Motivation

Fixes #6282.

When trailingSlash: true is enabled, generated Markdown asset URLs are treated like internal routes by the Link component. This appends a trailing slash to URLs such as /assets/files/example.docx, causing the browser to request an invalid asset path.

The MDX transform already knows when a link resolves to a real asset file. This change carries that information to Link through an internal marker so only confirmed asset URLs skip route-specific trailing-slash normalization. Normal internal routes keep their existing behavior.

Summary

  • mark resolved Markdown asset links so their exact URLs are preserved
  • consume the internal marker in Link without forwarding it to the DOM
  • leave trailing-slash handling unchanged for normal internal routes
  • add regression coverage for both the MDX transform and Link behavior

Test plan

  • pnpm test packages/docusaurus/src/client/exports/__tests__/Link.test.tsx packages/docusaurus-mdx-loader/src/remark/transformLinks/__tests__/index.test.ts
  • pnpm --filter @docusaurus/core build
  • pnpm --filter @docusaurus/mdx-loader build
  • scoped ESLint and Oxfmt checks on all changed TypeScript files

All 38 targeted tests pass, and both affected packages build successfully with Node.js 24.14.

Test links

Related issues/PRs

This contribution was AI-assisted. The implementation and generated changes were manually reviewed and verified.

@Sudemc
Sudemc requested review from Josh-Cena and slorber as code owners July 28, 2026 08:38
@meta-cla

meta-cla Bot commented Jul 28, 2026

Copy link
Copy Markdown

Hi @Sudemc!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@netlify

netlify Bot commented Jul 28, 2026

Copy link
Copy Markdown

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit 2d8f288
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/6a686a9af91310000802a5e8
😎 Deploy Preview https://deploy-preview-12323--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@Sudemc Sudemc changed the title Fix/asset link trailing slash ready fix: preserve asset URLs when trailingSlash is enabled Jul 28, 2026
@meta-cla

meta-cla Bot commented Jul 28, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the CLA Signed Signed Facebook CLA label Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

asset links with trailing slash true can be broken

1 participant