mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
## 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)
91 lines
3.0 KiB
TypeScript
91 lines
3.0 KiB
TypeScript
import { clientSdkIds } from '~/content/navigation.references'
|
|
import { BASE_PATH } from '~/lib/constants'
|
|
import MARKDOWN_SLUGS from '~/public/markdown/manifest.json'
|
|
import { negotiateMarkdown } from 'common/markdown-negotiation'
|
|
import { isbot } from 'isbot'
|
|
import { NextResponse, type NextRequest } from 'next/server'
|
|
|
|
const REFERENCE_PATH = `${BASE_PATH ?? ''}/reference`
|
|
const GUIDES_PATH = `${BASE_PATH ?? ''}/guides`
|
|
const GUIDES_MARKDOWN_SLUGS = new Set(MARKDOWN_SLUGS)
|
|
|
|
export function proxy(request: NextRequest) {
|
|
const url = new URL(request.url)
|
|
const { pathname } = url
|
|
|
|
if (pathname.startsWith(GUIDES_PATH + '/')) {
|
|
const isMdSuffix = pathname.endsWith('.md')
|
|
const slug = pathname.replace(`${GUIDES_PATH}/`, '').replace(/\.md$/, '')
|
|
const decision = negotiateMarkdown(
|
|
{ acceptHeader: request.headers.get('accept') ?? '' },
|
|
{ hasMarkdownVariant: GUIDES_MARKDOWN_SLUGS.has(slug), isMarkdownSuffix: isMdSuffix }
|
|
)
|
|
|
|
if (decision === 'not-acceptable') {
|
|
return new NextResponse('Not Acceptable', {
|
|
status: 406,
|
|
headers: { 'Cache-Control': 'no-store', Vary: 'Accept' },
|
|
})
|
|
}
|
|
|
|
if (decision === 'markdown') {
|
|
const rewriteUrl = new URL(url)
|
|
rewriteUrl.pathname = `${BASE_PATH ?? ''}/api/guides-md/${slug}`
|
|
return NextResponse.rewrite(rewriteUrl)
|
|
}
|
|
}
|
|
|
|
if (!pathname.startsWith(REFERENCE_PATH)) {
|
|
return NextResponse.next()
|
|
}
|
|
|
|
if (isbot(request.headers.get('user-agent'))) {
|
|
let [, lib, maybeVersion, ...slug] = pathname.replace(REFERENCE_PATH, '').split('/')
|
|
|
|
if (clientSdkIds.includes(lib)) {
|
|
const version = /^v\d+$/.test(maybeVersion) ? maybeVersion : undefined
|
|
if (!version) {
|
|
slug = [maybeVersion, ...slug]
|
|
}
|
|
|
|
if (slug.length > 0) {
|
|
const rewriteUrl = new URL(url)
|
|
rewriteUrl.pathname = (BASE_PATH ?? '') + '/api/crawlers'
|
|
return NextResponse.rewrite(rewriteUrl)
|
|
}
|
|
}
|
|
}
|
|
|
|
const [, lib, maybeVersion] = pathname.replace(REFERENCE_PATH, '').split('/')
|
|
|
|
if (lib === 'cli') {
|
|
const rewritePath = [REFERENCE_PATH, 'cli'].join('/')
|
|
return NextResponse.rewrite(new URL(rewritePath, request.url))
|
|
}
|
|
|
|
// Spike (DOCS-1268): only the bare /reference/api needs normalizing now.
|
|
// /reference/api/<slug> has its own statically generated page — don't
|
|
// collapse it back to the monolith.
|
|
if (lib === 'api' && !maybeVersion) {
|
|
const rewritePath = [REFERENCE_PATH, 'api'].join('/')
|
|
return NextResponse.rewrite(new URL(rewritePath, request.url))
|
|
}
|
|
|
|
if (lib?.startsWith('self-hosting-')) {
|
|
const rewritePath = [REFERENCE_PATH, lib].join('/')
|
|
return NextResponse.rewrite(new URL(rewritePath, request.url))
|
|
}
|
|
|
|
if (clientSdkIds.includes(lib)) {
|
|
const version = /^v\d+$/.test(maybeVersion) ? maybeVersion : null
|
|
const rewritePath = [REFERENCE_PATH, lib, version].filter(Boolean).join('/')
|
|
return NextResponse.rewrite(new URL(rewritePath, request.url))
|
|
}
|
|
|
|
return NextResponse.next()
|
|
}
|
|
|
|
export const config = {
|
|
matcher: ['/reference/:path*', '/guides/:path*'],
|
|
}
|