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
|
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. |
68177be to
af4b042
Compare
|
Hey @BrianSeong99! Thanks for the review, and sorry for the delay. Rebased onto latest I added a Let me know if you'd like anything else! |
…eck CI Normalize internal markdown links to source-relative .md and convert <Card href> to <Card docId>, so resolution no longer depends on URL shape. The normalizer defaults to docs/ (check mode stays green against the committed tree) and takes --all to also heal versioned_docs snapshots at deploy time. Adds check:doc-links / normalize-doc-links[:all] scripts, a deploy-time whole-tree normalize step, and a pull_request guard that fails on un-normalized current docs.
Generated by `npm run normalize-doc-links`.
af4b042 to
1317391
Compare
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.