Skip to content

Fix: add redirects for markdown docs - #1817

Merged
djfarrelly merged 6 commits into
mainfrom
fix/md-docs-redirects
Aug 3, 2026
Merged

Fix: add redirects for markdown docs#1817
djfarrelly merged 6 commits into
mainfrom
fix/md-docs-redirects

Conversation

@djfarrelly

Copy link
Copy Markdown
Member

Our redirects do not also handle the markdown docs like docs-markdown so some of those URLs dead end. This takes all the redirects and also copies them relative to the docs-markdown URLs as well so LLMs/scrapers aren't getting 404s.

Source: I pulled log data over a 24h period and saw lots of these.

@vercel

vercel Bot commented Jul 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
website Ready Ready Preview Aug 3, 2026 7:52pm

Request Review

@patrickholcomb9 patrickholcomb9 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice flag & fix, Dan - sorry for missing these md redirects! lgtm!

The route and middleware.ts each set a rel="canonical" Link header, so
responses carried two. They disagreed whenever a redirect destination
carried a fragment (/docs/frameworks/express resolves to
.../serving-inngest-functions#framework-express, which the route dropped),
and crawlers ignore conflicting canonicals outright.

Middleware owns it now: it resolves the same redirects and always names
the production origin, which is what a canonical needs to say from a
preview deploy.
/docs-markdown returned 400 "Missing 'path' query parameter" — there is no
such param; the empty slug was rejected before the lookup could reach
pages/docs/index.mdx. /blog-markdown 404'd because only a [slug] route
existed, so walking up from a post URL landed on nothing. Both are entry
points agents reach for first.

The blog index body is the listing /blog.txt already built, so that logic
moves to a shared blog-index module rather than being duplicated. /blog.txt
output is byte-identical.
@gester-bot

gester-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

Automated re-review could not be completed: the sandbox environment failed to check out the repository (repeated checkout_pr/run_command failures with no output). Please re-trigger the review.

@gester-bot gester-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unable to complete this re-review: the sandbox tooling (checkout_pr and run_command) failed repeatedly with no usable output, so I could not fetch the diff or verify any changes since the last review. No findings are reported here to avoid guessing; please re-run the review once the environment is functional.


Re-review (2026-07-28): Unable to perform this re-review: the sandbox failed to check out the repository across many retries (git lock errors / unresponsive shell), so no diff could be inspected and no new findings could be verified. Posted a status comment on the PR; please re-run the review once the environment is available.


Re-review (2026-07-28): Unable to complete this review: repeated sandbox/tooling failures prevented checking out the PR or running any commands (every call returned exit=null), so the diff could not be inspected. No findings can be reported without verifying against the actual code — please re-trigger the review.


Re-review (2026-07-29): Reviewed the full diff (redirects.mjs extraction, docs-markdown/blog-markdown routing, middleware canonical logic, and the bulk link updates). The logic checks out against manual testing (chained redirects, versionless TypeScript path resolution, empty-slug docs index) — the one gap worth calling out is test coverage for the new redirect-resolution logic.


Re-review (2026-08-03): Re-reviewed the two new commits since last pass: the mechanical /docs link updates across content/pages files, and the new redirects.test.mjs. The test file directly addresses the previously-open finding (missing coverage for resolveRedirect/resolveDocsPath), with solid behavior tests plus useful table invariants (no dupes, no self-refs, chains terminate, destinations exist, no stale destinations). No new issues found.


Re-review (2026-08-03): No material changes since the last review — the new commit is just a merge from main bringing in unrelated changes (pricing/events pages, Cloudflare docs, etc.); none of the PR's core files (redirects.mjs, docs-markdown route, middleware, next.config) changed. Nothing new to flag.

@gester-bot

gester-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

Unable to complete this re-review: the sandbox environment is currently failing to clone/checkout the repository (git lock errors, "not a git repository", and unresponsive shell commands). No code could be inspected, so no review findings can be verified at this time. Please re-trigger the review once the environment is stable.

@gester-bot

gester-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

Automated review could not be completed: the sandbox tooling failed to check out the repository (checkout_pr) and all subsequent shell commands returned no output/exit=null, likely due to an infrastructure issue unrelated to this PR. Please re-run the review.

347 links across the site pointed at URLs that only resolve via a 308 in
the redirect table. They worked, which is why they accumulated, but each
one costs a redirect hop and they were the source of the 404s in the
markdown mirror, where no redirect exists to paper over them.

Rewritten to the destination the redirect table already resolves to,
following chains where present (/docs/functions/retries took two hops).
Fragments and ?ref= tags are preserved verbatim.

  207  pages/docs
  100  content/blog, content/changelog, shared/Patterns/_patterns
   38  link values in components/shared/app/pages
    2  content/customers

Two files are deliberately untouched: shared/Docs/LanguageStore.ts uses
these paths as prefix-matching logic rather than links, and rewriting
them would break SDK language detection; and a comment in the
docs-markdown route that cites a redirect as an example.
Comment thread redirects.mjs
const at = pathname.search(/[?#]/);
return at === -1
? [pathname, ""]
: [pathname.slice(0, at), pathname.slice(at)];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New, non-trivial logic (resolveRedirect's chain-following/cycle-guard and resolveDocsPath's versionless-TypeScript-path handling) ships with no unit tests, despite being the core of this PR's fix and being consumed by three different call sites (next.config.mjs, middleware.ts, docs-markdown route). A regression here (e.g. in the cycle guard or suffix handling) would silently break canonical tags or 404 the markdown mirror. Consider adding a small test file (the repo already has a precedent in mdx/utils/docs.test.ts using node:test) covering multi-hop chains, fragment preservation, and the versionless-typescript rewrite.

Covers the resolver logic and, more usefully, invariants over the redirect
table itself: no duplicate or self-referencing sources, every chain
terminates, every /docs destination has a page behind it, and no
destination is itself a redirect source. That last set is what catches the
rot that produced the markdown-mirror 404s, since a stale entry breaks the
table long before anyone notices a bad link.

Behaviour cases are pinned to real entries, including the ordering bug
(reference/typescript/functions/errors must resolve via the redirect, not
get pinned to a version directory with no file) and fragment inheritance
across a chain (frameworks/express).

Verified by mutation: breaking chain following, fragment inheritance, or
the redirect step, and planting a rotted or duplicate entry, each fail the
suite. pnpm test now runs this alongside the existing docs-markdown test.
@djfarrelly
djfarrelly merged commit 3ececdf into main Aug 3, 2026
5 of 6 checks passed
@djfarrelly
djfarrelly deleted the fix/md-docs-redirects branch August 3, 2026 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants