Commit Graph
4 Commits
Author SHA1 Message Date
Miranda Limonczenko e44837c256 feat(docs): point every docs page at llms.txt in HTML and markdown (#53965)
Closes DOCS-1756

## Problem

No docs page tells an agent that `llms.txt` exists or that a markdown
version is available. Agents that send `Accept: text/markdown` already
get markdown, but agents that fetch HTML have no signal to try the
markdown path.


## Solution

- **HTML:** add a visually hidden directive as the first child of
`<body>` in the root layout, so it comes before the navigation on every
guide and reference page. It links to
`https://supabase.com/docs/llms.txt` and says guide pages have a
markdown version at the same path with `.md` appended, before any query
string or fragment. It's `sr-only` and `aria-hidden`, and the link has
`tabindex="-1"`.
- **Crawler HTML:** bot requests for SDK reference pages are rewritten
to `/api/crawlers`, which skips the root layout. The same directive goes
before its `<nav>`.
- **Markdown:** add a sentence linking `llms.txt` to the "Note for AI
agents" blockquote in the guides markdown route. The agent feedback page
skips the feedback text to avoid linking to itself, but it keeps the
`llms.txt` line.
- Add `LLMS_TXT_URL` and `LLMS_TXT_DIRECTIVE_HTML` to
`common/markdown-affordance`, and reuse `LLMS_TXT_URL` in `proxy.ts`.

The directive limits the `.md` claim to guides, because reference `.md`
requests 404. It doesn't say `llms.txt` lists every page.

The link targets `/docs/llms.txt`, the docs index that AFDocs scores for
the `/docs` base URL. #53968 makes it a real file. Until that merges,
`/docs/llms.txt` 308-redirects to the site-wide `/llms.txt`, so the link
works in either merge order.

## Manual testing

1. Open a Vercel preview guide page and view source. Confirm the
`llms.txt` directive comes before the navigation markup.
2. Open a reference page and confirm the same.
3. Confirm the directive isn't visible and isn't tabbable.
4. Request a reference section page with a bot user agent, such as `curl
-A Googlebot`, and confirm the directive comes before `<nav>`.
5. Request a guide with `.md` appended and confirm the opening
blockquote links `llms.txt`.
6. Request `/docs/guides/ai-tools/agent-feedback.md` and confirm the
opening blockquote links `llms.txt`.
7. Run AFDocs against the preview and confirm `llms-txt-directive-html`
and `llms-txt-directive-md` pass.
2026-11-24 15:02:23 -08:00
Miranda Limonczenko f59c795eb5 feat(docs): render Option 1 on the server when the variant is forced (#52735)
Closes DOCS-1520

## Problem

The original PR was only client-side. This is adding server-side
integration.

The docs-nav evals fetch each page's HTML with no JavaScript and add
`?docs-ia-mvp-v1=option-1` to every request. The option-1 arm gets the
control navigation anyway.

Guide pages are statically generated, so the server can't read the query
parameter. `useIaNavVariant` reads the override from the URL after the
page loads, so the fetched HTML always has today's nav, hidden with an
`invisible` class.

The top nav dropdowns have a second gap. Their panels mount on the
client, so their links are not in the server HTML for either variant.
Every eval case starts at `/docs`, where those links are the only way
into the Option 1 groups.

## Solution

- **Rewrite option-1 requests:** `proxy.ts` sends `/docs` and guide
pages with `?docs-ia-mvp-v1=option-1` to `/docs/ia/option-1/…`. Pages
there render on the first request and are then cached, so nothing is
added to the build. Requests without the parameter, and `.md` requests,
are not rewritten.
- **Read the variant from the route:** `IaNavRouteProvider`, in the root
layout, reads the variant from the layout segments. `useIaNavVariant`
returns it on the server and records no PostHog exposure for it.
`useIaNavReady` is ready at once, so the nav has no `invisible` class.
- **Strip the route prefix:** on the server, `usePathname` returns the
rewritten path. The nav components, breadcrumbs, and `AiTools` use
`useDocsPathname`, which strips the `/ia/option-1` prefix.
- **Breadcrumbs follow the variant:** they resolve from the visitor's
nav config, not always today's.
- **Top nav subheads in the HTML:** a `<noscript>` block next to the top
nav lists the dropdown links for the visitor's variant, inside an
`sr-only` nav. Browsers with JavaScript ignore it.
- **No index for the route:** direct visits to `/docs/ia/option-1/…` get
`noindex`. Canonical URLs point to the real guide.

**Not changed:**

- **Reference pages:** they keep today's nav, even with the parameter.
- **Config pages:** the five generated config pages under `self-hosting`
and `local-development/cli` are not in the markdown manifest, so they
keep today's nav too.
- **Links:** they don't carry the query parameter, so a click in the
browser leaves the forced variant. This was already the case before this
PR.
- **Conflicts with #52679:** it changes the same hooks. Whichever PR
merges second needs a rebase.

## Review instructions

`grep -c` counts the lines of server HTML that contain the text. A count
of 1 or more means the text is in the HTML that an agent fetches without
JavaScript. A count of 0 means it is not.

1. Run `curl -s
"https://docs-git-docs-ia-option-1-server-render-supabase.vercel.app/docs/guides/auth/sessions?docs-ia-mvp-v1=option-1"
| grep -c "Run and manage"`. The count is 1 or more. "Run and manage" is
an Option 1 top nav label, so this checks that the parameter gets Option
1's nav from the server.
2. Run `curl -s
"https://docs-git-docs-ia-option-1-server-render-supabase.vercel.app/docs/guides/auth/sessions"
| grep -c "Run and manage"`. The count is 0. This checks that a request
without the parameter still gets today's nav.
3. Run `curl -s
"https://docs-git-docs-ia-option-1-server-render-supabase.vercel.app/docs?docs-ia-mvp-v1=option-1"
| grep -c "guides/platform/ssl-enforcement"`. The count is 1 or more.
The home page has no sidebar, and this link sits only in the "Run and
manage" dropdown, so this checks that the top nav subhead links are in
the server HTML.
4. Run `curl -s -o /dev/null -w "%{http_code}"
"https://docs-git-docs-ia-option-1-server-render-supabase.vercel.app/docs/guides/auth.md?docs-ia-mvp-v1=option-1"`.
It returns `200`. This checks that the markdown version still loads with
the parameter.
5. Open
[/docs/guides/auth](https://docs-git-docs-ia-option-1-server-render-supabase.vercel.app/docs/guides/auth)
in a browser and hover over the top nav. You see today's nav and
dropdowns.

## Checklist

Check all before review:

- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [ ] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style
guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
2026-11-06 19:46:37 +00:00
Pamela Chia 2e63060c59 fix(docs): serve markdown 404s for guessed .md urls (#52293)
Coding agents guess docs URLs that don't exist: markdown variants of
pages that have no markdown (`/docs/reference/<sdk>/<fn>.md`,
`/docs/guides/<slug>.md`) and `/docs/llms.txt`. Reference guesses get an
empty-body 404 from the crawler renderer for bot user agents and the
full HTML reference for browsers, and the rest get the HTML 404 page, so
the agent never learns where the content lives. Reference `.md` guesses
are about half of coding-agent docs 4xx, and guide `.md` guesses about a
tenth.

**Changed:**
- **Reference `.md` guesses**: the docs proxy answers every
`/docs/reference/**.md` request itself, for any user agent and before
the crawler rewrite, with a markdown 404 (`no-store`) linking the HTML
page and the SDK's full markdown reference (`/llms/js.txt`,
`/llms/dart.txt`, and so on), or `/llms.txt` for references without one.
- **Unknown guide `.md` guesses**: guide `.md` requests whose slug has
no markdown variant get the same markdown 404 instead of the HTML 404.
The body says there is no markdown version of the page, because a few
real guide pages (CLI config, self-hosting config, troubleshooting
indexes) are TSX-only. Known guides and Accept-negotiated requests
without `.md` are unchanged.
- **`/docs/llms.txt`**: I added a permanent www redirect to `/llms.txt`,
next to the existing `/docs/reference/llms.md` redirect.

**Note:** the `.md` check in `proxy.ts` catches every reference `.md`
URL, so it has to be narrowed when per-function reference markdown
ships, or it will 404 those files.

## To test

Tested on the PR previews (docs deployment for the 404s, www deployment
for the redirect):
- [x] `curl -sD - -A 'curl/8.7.1'
<docs-preview>/docs/reference/javascript/select.md`: expect 404,
`content-type: text/markdown`, `cache-control: no-store`, and a body
linking `https://supabase.com/docs/reference/javascript/select` and
`https://supabase.com/llms/js.txt`
- [x] Repeat for `dart/select.md`, `python/select.md`,
`cli/supabase-init.md` and `api/v1-list-all-projects.md`: expect the
matching `/llms/<sdk>.txt`
- [x] Repeat `javascript/select.md` with a browser user agent: expect
the same markdown 404
- [x] `curl -sD - <docs-preview>/docs/guides/doesnotexist.md`: expect
404 markdown with `no-store`, linking `https://supabase.com/llms.txt`
- [x] `curl -s
<docs-preview>/docs/guides/local-development/cli/config.md`: expect 404
markdown linking
`https://supabase.com/docs/guides/local-development/cli/config`
- [x] `curl -sD - <docs-preview>/docs/guides/database/overview.md`:
expect 200 markdown, unchanged
- [x] Open `<docs-preview>/docs/guides/doesnotexist` in a browser:
expect the branded HTML 404, unchanged
- [x] `curl -sIL -o /dev/null -w '%{num_redirects} %{http_code}\n'
<www-preview>/docs/llms.txt`, once with a browser user agent and once
with `Googlebot/2.1`: expect `1 200`

## Linear
- fixes GROWTH-1325
2026-10-27 01:21:01 +08:00
Alexis Aguilar 44386580e3 feat(docs): upgrade to Next.js 16 (#52045)
## Problem

The docs site (`apps/docs`) is still on Next.js 15, which is close to
the end of its support window under the [Next.js support
policy](https://nextjs.org/support-policy). Resolves
[DOCS-1485](https://linear.app/supabase/issue/DOCS-1485/upgrade-the-docs-site-to-nextjs-16).

## Solution

Upgrades `apps/docs` to Next.js 16.3.6. The scope is limited to what
Next.js 16 requires, so existing routes, redirects, and responses stay
the same.

- **Dependencies:** `next` uses the workspace catalog, and `@next/mdx`
and `@next/bundle-analyzer` are bumped to 16.3.6.
- **Webpack:** `dev` and `build` run with `--webpack`, because the docs
config loads `.include`, `.toml`, and YAML files through webpack, and
the MDX remark plugins have non-serializable options.
- **Proxy:** `middleware.ts` is renamed to `proxy.ts`.
- **Cache revalidation:** `revalidateTag` is called with `{ expire: 0 }`
to keep immediate expiration.
- **Images:** `images.localPatterns` allows guide images with `?v=N`
cache-busting query strings. Without it, those pages return 500.
- **Scroll behavior:** `data-scroll-behavior="smooth"` on `<html>` keeps
route changes jumping to the top instantly.
- **Config:** the `eslint` key is removed from `next.config.mjs`, and
Sentry options use their new names.
- **`next-env.d.ts`:** gitignored, like in the other apps, because
Next.js 16 regenerates it differently for `dev` and `typegen`.

### Dependency on the marketing site upgrade

The docs chat edge function (`/api/ai/docs`) stays under the Vercel Edge
Function size limit because #52001
([FE-4673](https://linear.app/supabase/issue/FE-4673/upgrade-the-marketing-site-to-nextjs-16))
removed `js-tiktoken` from `ai-commands`. This branch is based on
`master` with that change.

## Known limitations

- `proxy.ts` runs on the Node.js runtime instead of edge.
- `nuqs` v1 doesn't declare support for Next.js 15 or 16. The
troubleshooting filters work on Next.js 16, but the dependency is
outside its supported range.
- `next/legacy/image` and `unstable_cache` are deprecated but still
supported.
- Tabs opened before the deploy keep running the Next.js 15 client. On
their next client-side navigation, the router loads the page in full
instead. Docs pages are prerendered, so these requests don't reach the
renderer or report errors to Sentry.

## Review instructions

1. Run `pnpm --filter=docs typecheck` and `pnpm --filter=docs
test:local`.
2. Run `pnpm dev:docs` and open a guide, a client library reference
page, and `/guides/troubleshooting` with a filter applied.
3. Check the Vercel preview against production docs: every sitemap URL
returns the same status code, and redirects, `.md` responses, search,
and the AI chat behave the same. A local production build already
matches production for the following:
   - All 2,564 sitemap URLs
- The redirects in `next.config.mjs`, except where a www redirect
handles the path first
   - `.md` negotiation, including the 406 response
   - Reference rewrites, including bot requests

Search and the AI chat need the preview, because they depend on
production data and keys.
4. Confirm the preview build has enough memory. Locally, `next build`
peaked at about 4 GB.

## Future work

- Upgrade `nuqs` to v2.
- Replace `next/legacy/image` with `next/image`.
- Replace `unstable_cache` with `use cache`.

## Checklist

Check all before review:

- [ ] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [ ] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style
guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
2026-10-21 13:16:54 -07:00