Skip to content

site/api-md: Prerender markdown routes at build time; enable Fluid compute - #1912

Open
marcleblanc2 wants to merge 1 commit into
ci/vercel-ignore-non-site-changesfrom
site/static-md-routes-and-fluid
Open

site/api-md: Prerender markdown routes at build time; enable Fluid compute#1912
marcleblanc2 wants to merge 1 commit into
ci/vercel-ignore-non-site-changesfrom
site/static-md-routes-and-fluid

Conversation

@marcleblanc2

Copy link
Copy Markdown
Contributor

Vercel audit items 5a and 5b (see #1905, dev/TODO.md item 5). Stacked on #1901 because both edit vercel.json; merge #1901 first, then retarget this to main.

What changes

/api/md/[...slug] (serves <page>.md, which the middleware rewrites to this route):

  • generateStaticParams() returns every post's slug, so Next writes each markdown response to disk during next build (.next/server/app/api/md/**/*.body). Vercel serves those from the CDN: no function invocation, no cold start.
  • dynamicParams = false makes unknown slugs 404 at the edge without invoking a function. Behaviour change: an unknown .md URL now gets the site's HTML 404 page (like any other unknown URL) instead of the plain-text Not Found the function used to return.
  • The root index.mdx is skipped: its flattened path is empty and a catch-all needs at least one segment. /api/md was never a valid URL for this route; the first build attempt failed on exactly that.

vercel.json: "fluid": true turns on Fluid compute for the remaining functions (/api/og/[...path], the [...slug] page renderer for non-prerendered paths). Fluid lets one instance handle many concurrent requests instead of one cold start per request, and bills active CPU time rather than wall-clock. Memory/CPU size still lives in the dashboard (Settings → Functions), not in vercel.json.

Verification (local)

  • pnpm build: /api/md/[...slug] shows as (SSG) with ~500 paths; build time unchanged (about 40 s locally).
  • pnpm start, then:
    • /api/md/admin/config/site-config → 200 text/markdown, 47 902 B
    • /api/md/cli/references/auth → 200 text/markdown, body starts with # src auth
    • /api/md/does/not/exist → 404

Verification (after the preview deploys)

Compare against production for the same URL:

for u in https://sourcegraph.com/docs/admin/config/site-config.md <preview>/docs/admin/config/site-config.md; do
  curl -so /dev/null -w '%{http_code} %{time_total}s\n' -D - "$u" | grep -iE 'x-vercel-cache|^[0-9]{3} '
done

Expect the preview to answer with x-vercel-cache: HIT (or PRERENDER) and a faster time_total on cold paths. For /api/og/..., expect similar or better latency under Fluid; nothing should be slower.

Every doc page's markdown is now written as a static file during the
build, so .md requests are served from the CDN instead of invoking a
serverless function per request. Unknown slugs 404 without a function
call (dynamicParams = false).

vercel.json gains "fluid": true so the remaining functions (/api/og,
the catch-all page renderer) share instances instead of cold-starting
one per concurrent request.

Amp-Thread-ID: https://ampcode.com/threads/T-01a08e2d-682f-75dd-a050-cb9bf8888dac
Co-authored-by: Amp <amp@ampcode.com>
@vercel

vercel Bot commented Sep 11, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated
sourcegraph-docs Ready Ready Preview Sep 11, 2026 5:59am UTC

Request Review

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.

1 participant