fix: make docs links resolve consistently regardless of URL form#262
fix: make docs links resolve consistently regardless of URL form#262JereSalo wants to merge 2 commits into
Conversation
… query strings - traverse backtick-quoted spans inside markdown link text so labels like [`#[export_type]`] normalize correctly - skip fenced code blocks and HTML/MDX comments so example markdown isn't rewritten - bail out on Card hrefs with query strings since Card has no prop for them - regex uses mutually exclusive branches on first character to avoid catastrophic backtracking on math text
|
TLDR: Some links are broken/flaky in the miden docs, a good example to replicate this is by going to https://docs.miden.xyz/builder/smart-contracts/cross-component-calls/ and then on the first paragraph clicking on a relative link, it'll be broken. This is one of the edge cases this PR aims to fix, but at a structural level so that we fix it in all the docs. For more info read description. |
|
Thanks for digging into this @JereSalo — the repro is spot on. I ran a full-ingestion build of Heads up before you continue: the Core Concepts → Reference rename (#306) just merged. It moved Could you rebase onto the latest
I'd suggest dropping the bulk edits to the frozen Really appreciate the insight and the script — happy to review as soon as it's rebased. |
Problem
Links on the docs site break depending on how the user reaches a page. Docusaurus serves two URL forms, "index" links (they have sublinks) and "leaf" links (they don't have sublinks), and resolves relative links differently for each. When a page is loaded directly via its public URL, the browser appends a trailing
/, which makes Docusaurus treat it as an index. When the same page is reached via SPA navigation (clicking a link on another page) the trailing/is sometimes missing, so it is treated as a leaf. As a result, relative links on the page resolve to different absolute paths depending on how the user got there, and many of those paths do not exist.Examples:
For
cross-component-calls(a real leaf), opening the direct URL renders it as if it were an index, while reaching it via the SPA renders it as a leaf. Using the first method, subsequent relative clicks then resolve to the wrong path. Try accessing the link and then clicking on any highlighted word that takes you to another path, you'll see that if you opened the link as an URL you'll be redirected to an unexisting page.For
get-started(a real index), opening the direct URL works, but reaching it from https://docs.miden.xyz/ renders it as a leaf, breaking relative clicks on the page. Try entering from there and then go to any of the linked guides from there. In the case of the sublink "Installation" the resolved link is going to be https://docs.miden.xyz/builder/setup/installation instead of the correct one that is https://docs.miden.xyz/builder/get-started/setup/installation/. Notice that the former isbuilder/get-startedand the other one isbuilder/setup/installation.Goal
Make link resolution independent of the URL shape, and prevent the same issue from being reintroduced by future docs.
Changes
Core fix:
.md. Before:[Installation](./setup/installation). After:[Installation](./setup/installation.md). Docusaurus resolves.mdlinks from the docs source tree, so they work correctly in versioned docs and do not depend on the URL shape.docIdfor<Card>links. Before:<Card href="./setup/installation">. After:<Card docId="builder/get-started/setup/installation">. Docusaurus does not rewrite custom MDX props likehref, soCardnow resolves docs pages through Docusaurus metadata.Robustness:
npm run check:doc-links,npm run normalize-doc-links) so new or edited docs cannot reintroduce browser-relative internal links.A trailing
/no longer matters: links resolve consistently because they are referenced through Docusaurus' source-tree resolver instead of browser-relative URLs.I tested it locally and both edge cases I mentioned worked perfectly fine.