---
description: Next.js 16 rules (App Router): async request APIs, proxy.ts, caching APIs, removed config, security headers
globs: **/*.ts, **/*.tsx, **/*.js, **/*.jsx, **/*.mjs
alwaysApply: false
---
# Next.js 16 rules

This project uses Next.js 16 (checked against the official Next.js 16 upgrade guide and the latest 16.x release, 16.4, on 2026-11-09).
Most code examples online are Next.js 13-15. When unsure whether an API or config key still exists, read the docs bundled in `node_modules/next/dist/docs/` or https://nextjs.org/docs instead of guessing.

## Versions
- Node.js 20.9 or newer, TypeScript 5.1 or newer. Don't suggest Node.js 18.
- Don't add `--turbopack` or `--turbo` to scripts: Turbopack is already the default for `next dev` and `next build`.

## Request APIs are async only
- Always `await cookies()`, `await headers()`, `await draftMode()`.
- In pages, layouts, route handlers, `default.js` and metadata image files, `params` is a Promise: `const { slug } = await props.params`. In pages, `searchParams` is a Promise too.
- Use the generated helper types (`PageProps<'/blog/[slug]'>`, `LayoutProps`, `RouteContext`; run `npx next typegen`) instead of hand-written prop types.
- `opengraph-image`, `twitter-image`, `icon` and `apple-icon` functions get `params` and `id` as Promises: await them. `sitemap({ id })` gets `id` as a Promise<string>. `generateImageMetadata` still gets plain `params`.
- In Client Components that receive these Promises, unwrap them with React's `use()`.

## proxy.ts, not middleware.ts
- New request interception goes in `proxy.ts` (or `proxy.js`) and the exported function is named `proxy`. The `middleware` file name and export are deprecated.
- `proxy` always runs on the Node.js runtime and can't be configured. If the existing middleware needs the edge runtime, keep `middleware.ts` and say so; never rename it silently.
- Config flags with "middleware" in the name are renamed (for example `skipMiddlewareUrlNormalize` is now `skipProxyUrlNormalize`).

## Caching APIs
- `revalidateTag(tag, profile)` needs the second argument, for example `revalidateTag('posts', 'max')`. The one-argument form is deprecated.
- In a Server Action where the user must see their own change right away, use `updateTag(tag)` (Server Actions only). Use `refresh()` from `next/cache` to refresh the client router from a Server Action.
- Import `cacheLife` and `cacheTag` from `next/cache` without the `unstable_` prefix.
- Don't add `experimental.ppr`, `experimental_ppr`, `experimental.dynamicIO` or `experimental.useCache`: they are removed. `cacheComponents: true` is a different model, not a rename; don't turn it on just to finish an upgrade.
- Don't turn on `reactCompiler` just to finish an upgrade either; it is opt-in and slows builds.

## Config that no longer exists
- No `next lint` (removed) and no `eslint` key in next.config. Lint with the ESLint CLI (flat config) or Biome. `next build` no longer lints.
- No `serverRuntimeConfig`, `publicRuntimeConfig` or `getConfig()`. Use `process.env` on the server and `NEXT_PUBLIC_` variables for the client.
- Turbopack options go in top-level `turbopack`, not `experimental.turbopack`.
- A custom `webpack` config makes `next build` fail. Ask before switching the build to `--webpack`.
- No AMP (`next/amp`, `amp` config): removed.
- Every parallel route slot (`@slot`) needs a `default.js` that returns `null` or calls `notFound()`, or the build fails.
- Don't add `experimental.viewTransition` (removed in 16.3) or `experimental.appNewScrollHandler` (removed in 16.4).

## next/image
- Use `images.remotePatterns`, not `images.domains` (deprecated). Use `next/image`, not `next/legacy/image`.
- Defaults changed: `qualities` is `[75]` (other `quality` values are coerced to the closest allowed one), `minimumCacheTTL` is 4 hours, `16` is gone from `imageSizes`, at most 3 redirects, local IPs are blocked.
- A local `src` with a query string (`/photo.png?v=1`) needs a matching `images.localPatterns` entry with `search`.

## Security headers
- Set static security headers in `next.config` `headers()` with `source: '/(.*)'`, not in `proxy.ts`. Only use `proxy.ts` for a CSP if the app needs per-request nonces, and say that nonces force dynamic rendering.
- In development React needs `'unsafe-eval'` in `script-src`; never ship `'unsafe-eval'` to production.
- Use CSP `frame-ancestors` against clickjacking (it supersedes `X-Frame-Options`; keeping both is fine). `X-Content-Type-Options` only takes `nosniff`.
- After changing headers, check the deployed site's response headers, not just the build.

## Upgrading an older app
- Official helpers: `npx @next/codemod@canary upgrade latest`, then `npx @next/codemod@canary next-async-request-api .` (the upgrade codemod doesn't run that one). `npx @next/codemod@canary agents-md` points AGENTS.md at version-matched docs.
- After a codemod, search for leftover `UnsafeUnwrapped` casts and codemod error comments and fix them.
- A green build is not the finish line: run the app's tests and click through the routes the change touched.
