Skip to content

Commit c68d62d

Browse files
icyJosephabhishekmardiyavercel[bot]feedthejimcursoragent
authored
Backport documentation fixes for 16.1.x (#90655)
## Summary Backports documentation fixes and improvements from canary to the `next-16-1` branch. ### Included commits: - `757ab17e54` In-Depth Explanation of React Version Handling Doc (#89426) - `fe0bb2fc51` Next.js sticky scroll standards (#90197) - `d13d1ba23b` docs: improve form guide consistency and validation examples (#90361) - `c23f3434a3` docs: fixes typo in manifest.mdx regarding Route Handler note (#90394) - `dcf11d111b` docs: clarify that next upgrade is for 16.1.x+ (#90435) - `da0cbcce76` Add not-found.js / notFound() links to Status Codes section (#88332) - `ae79ae55eb` docs: add Docker Standalone and Docker Export examples to Deploying page (#90386) - `bb813afd49` docs(deploying): add Hostinger Web Apps Hosting to Node.js deployment options (#90246) - `15fcfb9ce4` docs: fix navigationType value and variable name in useReportWebVitals (#90599) - `080e1b3` docs: Accept header content negotiation (#90607) --------- Co-authored-by: Abhishek Mardiya <[email protected]> Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com> Co-authored-by: Jimmy Lai <[email protected]> Co-authored-by: Cursor Agent <[email protected]> Co-authored-by: Mary Lavanitha <[email protected]> Co-authored-by: Tyler Arthur <[email protected]> Co-authored-by: Karl Horky <[email protected]> Co-authored-by: Kristiyan Velkov <[email protected]> Co-authored-by: Wyatt Johnson <[email protected]> Co-authored-by: kristiyan.velkov <[email protected]> Co-authored-by: agneliutkiene <[email protected]> Co-authored-by: Mimori <[email protected]> Co-authored-by: Joseph <[email protected]>
1 parent 5214ac1 commit c68d62d

File tree

12 files changed

+180
-15
lines changed

12 files changed

+180
-15
lines changed

docs/01-app/01-getting-started/01-installation.mdx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ yarn add next@latest react@latest react-dom@latest
126126
bun add next@latest react@latest react-dom@latest
127127
```
128128

129-
> **Good to know**: The App Router uses [React canary releases](https://react.dev/blog/2023/05/03/react-canaries) built-in, which include all the stable React 19 changes, as well as newer features being validated in frameworks. The Pages Router uses the React version you install in `package.json`.
129+
> **Good to know**:
130+
>
131+
> - The `App Router` uses [React canary releases](https://react.dev/blog/2023/05/03/react-canaries) built-in, which include all the stable React 19 changes, as well as newer features being validated in frameworks, but you should still declare react and react-dom in package.json for tooling and ecosystem compatibility.
132+
> - The `Pages Router` uses the React version from your `package.json`.
130133
131134
Then, add the following scripts to your `package.json` file:
132135

docs/01-app/01-getting-started/04-linking-and-navigating.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ Next.js avoids this with client-side transitions using the `<Link>` component. I
158158

159159
Client-side transitions are what makes a server-rendered apps _feel_ like client-rendered apps. And when paired with [prefetching](#prefetching) and [streaming](#streaming), it enables fast transitions, even for dynamic routes.
160160

161+
Next.js also handles [scrolling to the top of the page](/docs/app/api-reference/components/link#scroll) during client-side transitions. If content scrolls behind a sticky or fixed header after navigation, you can fix this with CSS [`scroll-padding-top`](/docs/app/api-reference/components/link#scroll-offset-with-sticky-headers).
162+
161163
## What can make transitions slow?
162164

163165
These Next.js optimizations make navigation fast and responsive. However, under certain conditions, transitions can still _feel_ slow. Here are some common causes and how to improve the user experience:

docs/01-app/01-getting-started/17-deploying.mdx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,26 @@ Node.js deployments support all Next.js features. Learn how to [configure them](
3535
- [Flightcontrol](https://github.com/nextjs/deploy-flightcontrol)
3636
- [Railway](https://github.com/nextjs/deploy-railway)
3737
- [Replit](https://github.com/nextjs/deploy-replit)
38+
- [Hostinger](https://github.com/hostinger/deploy-nextjs)
3839

3940
## Docker
4041

41-
Next.js can be deployed to any provider that supports [Docker](https://www.docker.com/) containers. This includes container orchestrators like Kubernetes or a cloud provider that runs Docker.
42+
Next.js can be deployed to any provider that supports [Docker](https://www.docker.com/) containers. This includes container orchestrators like Kubernetes or a cloud provider that runs Docker. For containerization best practices, see the [Docker guide for React.js](https://docs.docker.com/guides/reactjs/).
4243

4344
Docker deployments support all Next.js features. Learn how to [configure them](/docs/app/guides/self-hosting) for your infrastructure.
4445

4546
> **Note for development:** While Docker is excellent for production deployments, consider using local development (`npm run dev`) instead of Docker during development on Mac and Windows for better performance. [Learn more about optimizing local development](/docs/app/guides/local-development).
4647
4748
### Templates
4849

49-
- [Docker](https://github.com/vercel/next.js/tree/canary/examples/with-docker)
50-
- [Docker Multi-Environment](https://github.com/vercel/next.js/tree/canary/examples/with-docker-multi-env)
50+
The following examples demonstrate best practices for containerizing Next.js applications:
51+
52+
- [Docker Standalone Output](https://github.com/vercel/next.js/tree/canary/examples/with-docker) - Deploy a Next.js application using `output: "standalone"` to generate a minimal, production-ready Docker image with only the required runtime files and dependencies.
53+
- [Docker Export Output](https://github.com/vercel/next.js/tree/canary/examples/with-docker-export-output) - Deploy a fully static Next.js application using `output: "export"` to generate optimized HTML files that can be served from a lightweight container or any static hosting environment.
54+
- [Docker Multi-Environment](https://github.com/vercel/next.js/tree/canary/examples/with-docker-multi-env) - Manage separate Docker configurations for development, staging, and production environments with different environment variables.
55+
56+
Additionally, hosting providers offer guidance on deploying Next.js:
57+
5158
- [DigitalOcean](https://github.com/nextjs/deploy-digitalocean)
5259
- [Fly.io](https://github.com/nextjs/deploy-fly)
5360
- [Google Cloud Run](https://github.com/nextjs/deploy-google-cloud-run)

docs/01-app/01-getting-started/18-upgrading.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ yarn next upgrade
3030
bunx next upgrade
3131
```
3232

33-
Next.js 15 and earlier do not support the `upgrade` command and need to use a separate package instead:
33+
Versions before Next.js 16.1.0 do not support the `upgrade` command and need to use a separate package instead:
3434

3535
```bash filename="Terminal"
3636
npx @next/codemod@canary upgrade latest

docs/01-app/02-guides/backend-for-frontend.mdx

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ nav_title: Backend for Frontend
44
description: Learn how to use Next.js as a backend framework
55
related:
66
title: API Reference
7-
description: Learn more about Route Handlers and Proxy
7+
description: Learn more about Route Handlers, Proxy, and Rewrites
88
links:
99
- app/api-reference/file-conventions/route
1010
- app/api-reference/file-conventions/proxy
11+
- app/api-reference/config/next-config-js/rewrites
1112
---
1213

1314
Next.js supports the "Backend for Frontend" pattern. This lets you create public endpoints to handle HTTP requests and return any content type—not just HTML. You can also access data sources and perform side effects like updating remote data.
@@ -178,6 +179,105 @@ export async function GET(request) {
178179

179180
Sanitize any input used to generate markup.
180181

182+
### Content negotiation
183+
184+
You can use [rewrites](/docs/app/api-reference/config/next-config-js/rewrites) with header matching to serve different content types from the same URL based on the request's `Accept` header. This is known as [content negotiation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Content_negotiation).
185+
186+
For example, a documentation site might serve HTML pages to browsers and raw Markdown to AI agents from the same `/docs/…` URLs.
187+
188+
**1. Configure a rewrite that matches the `Accept` header:**
189+
190+
```js filename="next.config.js"
191+
module.exports = {
192+
async rewrites() {
193+
return [
194+
{
195+
source: '/docs/:slug*',
196+
destination: '/docs/md/:slug*',
197+
has: [
198+
{
199+
type: 'header',
200+
key: 'accept',
201+
value: '(.*)text/markdown(.*)',
202+
},
203+
],
204+
},
205+
]
206+
},
207+
}
208+
```
209+
210+
When a request to `/docs/getting-started` includes `Accept: text/markdown`, the rewrite routes it to `/docs/md/getting-started`. A Route Handler at that path returns the Markdown response. Clients that do not send `text/markdown` in their `Accept` header continue to receive the normal HTML page.
211+
212+
**2. Create a Route Handler for the Markdown response:**
213+
214+
```ts filename="app/docs/md/[...slug]/route.ts" switcher
215+
import { getDocsMd, generateDocsStaticParams } from '@/lib/docs'
216+
217+
export async function generateStaticParams() {
218+
return generateDocsStaticParams()
219+
}
220+
221+
export async function GET(_: Request, ctx: RouteContext<'/docs/md/[...slug]'>) {
222+
const { slug } = await ctx.params
223+
const mdDoc = await getDocsMd({ slug })
224+
225+
if (mdDoc == null) {
226+
return new Response(null, { status: 404 })
227+
}
228+
229+
return new Response(mdDoc, {
230+
headers: {
231+
'Content-Type': 'text/markdown; charset=utf-8',
232+
Vary: 'Accept',
233+
},
234+
})
235+
}
236+
```
237+
238+
```js filename="app/docs/md/[...slug]/route.js" switcher
239+
import { getDocsMd, generateDocsStaticParams } from '@/lib/docs'
240+
241+
export async function generateStaticParams() {
242+
return generateDocsStaticParams()
243+
}
244+
245+
export async function GET(_, { params }) {
246+
const { slug } = await params
247+
const mdDoc = await getDocsMd({ slug })
248+
249+
if (mdDoc == null) {
250+
return new Response(null, { status: 404 })
251+
}
252+
253+
return new Response(mdDoc, {
254+
headers: {
255+
'Content-Type': 'text/markdown; charset=utf-8',
256+
Vary: 'Accept',
257+
},
258+
})
259+
}
260+
```
261+
262+
The [`Vary: Accept`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Vary) response header tells caches that the response body depends on the `Accept` request header. Without it, a shared cache could serve a cached Markdown response to a browser (or vice versa). Most hosting providers already include the `Accept` header in their cache key, but setting `Vary` explicitly ensures correct behavior across all CDNs and proxy caches.
263+
264+
`generateStaticParams` lets you pre-render the Markdown variants at build time so they can be served from the edge without hitting the origin server on every request.
265+
266+
**3. Test it with `curl`:**
267+
268+
```bash
269+
# Returns Markdown
270+
curl -H "Accept: text/markdown" https://example.com/docs/getting-started
271+
272+
# Returns the normal HTML page
273+
curl https://example.com/docs/getting-started
274+
```
275+
276+
> **Good to know:**
277+
>
278+
> - The `/docs/md/...` route is still directly accessible without the rewrite. If you want to restrict it to only serve via the rewrite, use [`proxy`](/docs/app/api-reference/file-conventions/proxy) to block direct requests that don't include the expected `Accept` header.
279+
> - For more advanced negotiation logic, you can use [`proxy`](/docs/app/api-reference/file-conventions/proxy) instead of rewrites for more flexibility.
280+
181281
### Consuming request payloads
182282

183283
Use Request [instance methods](https://developer.mozilla.org/en-US/docs/Web/API/Request#instance_methods) like `.json()`, `.formData()`, or `.text()` to access the request body.

docs/01-app/03-api-reference/02-components/link.mdx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,58 @@ export default function Home() {
884884

885885
</PagesOnly>
886886

887+
### Scroll offset with sticky headers
888+
889+
Because Next.js skips sticky and fixed positioned elements when finding the scroll target, content may end up behind a sticky header after navigation. For example, if your layout has a sticky header:
890+
891+
```tsx filename="app/layout.tsx" switcher
892+
import './globals.css'
893+
894+
export default function RootLayout({
895+
children,
896+
}: {
897+
children: React.ReactNode
898+
}) {
899+
return (
900+
<html lang="en">
901+
<body>
902+
<header className="sticky top-0 h-16 bg-white">
903+
{/* Navigation */}
904+
</header>
905+
{children}
906+
</body>
907+
</html>
908+
)
909+
}
910+
```
911+
912+
```jsx filename="app/layout.js" switcher
913+
import './globals.css'
914+
915+
export default function RootLayout({ children }) {
916+
return (
917+
<html lang="en">
918+
<body>
919+
<header className="sticky top-0 h-16 bg-white">
920+
{/* Navigation */}
921+
</header>
922+
{children}
923+
</body>
924+
</html>
925+
)
926+
}
927+
```
928+
929+
You can account for its height using [`scroll-padding-top`](https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-padding-top) on the scroll container:
930+
931+
```css filename="app/globals.css"
932+
html {
933+
scroll-padding-top: 64px; /* Match the height of your sticky header */
934+
}
935+
```
936+
937+
This is a browser CSS property that offsets scroll-based positioning. It applies whenever Next.js uses the native [`scrollIntoView()`](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView) API, including hash fragment (`#id`) navigation. Alternatively, you can use [`scroll-margin-top`](https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-margin-top) on individual target elements instead of setting a global offset.
938+
887939
### Prefetching links in Proxy
888940

889941
It's common to use [Proxy](/docs/app/api-reference/file-conventions/proxy) for authentication or other purposes that involve rewriting the user to a different page. In order for the `<Link />` component to properly prefetch links with rewrites via Proxy, you need to tell Next.js both the URL to display and the URL to prefetch. This is required to avoid un-necessary fetches to proxy to know the correct route to prefetch.

docs/01-app/03-api-reference/03-file-conventions/01-metadata/manifest.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Add or generate a `manifest.(json|webmanifest)` file that matches the [Web Manif
2121

2222
Add a `manifest.js` or `manifest.ts` file that returns a [`Manifest` object](#manifest-object).
2323

24-
> Good to know: `manifest.js` is special Route Handlers that is cached by default unless it uses a [Dynamic API](/docs/app/guides/caching#dynamic-apis) or [dynamic config](/docs/app/guides/caching#segment-config-options) option.
24+
> Good to know: `manifest.js` is a special Route Handler that is cached by default unless it uses a [Dynamic API](/docs/app/guides/caching#dynamic-apis) or [dynamic config](/docs/app/guides/caching#segment-config-options) option.
2525
2626
```ts filename="app/manifest.ts" switcher
2727
import type { MetadataRoute } from 'next'

docs/01-app/03-api-reference/03-file-conventions/not-found.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Next.js provides two conventions to handle not found cases:
1010

1111
## `not-found.js`
1212

13-
The **not-found** file is used to render UI when the [`notFound`](/docs/app/api-reference/functions/not-found) function is thrown within a route segment. Along with serving a custom UI, Next.js will return a `200` HTTP status code for streamed responses, and `404` for non-streamed responses.
13+
The **not-found** file is used to render UI when the [`notFound`](/docs/app/api-reference/functions/not-found) function is thrown within a route segment. Along with serving a custom UI, Next.js will return a `200` HTTP status code for streamed responses, and `404` for non-streamed responses (see [Status Codes](/docs/app/api-reference/file-conventions/loading#status-codes) for details about SEO).
1414

1515
```tsx filename="app/not-found.tsx" switcher
1616
import Link from 'next/link'

docs/01-app/03-api-reference/04-functions/not-found.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: notFound
33
description: API Reference for the notFound function.
44
---
55

6-
The `notFound` function allows you to render the [`not-found file`](/docs/app/api-reference/file-conventions/not-found) within a route segment as well as inject a `<meta name="robots" content="noindex" />` tag.
6+
The `notFound` function allows you to render the [`not-found file`](/docs/app/api-reference/file-conventions/not-found) within a route segment as well as inject a [`<meta name="robots" content="noindex" />`](/docs/app/api-reference/file-conventions/loading#status-codes) tag for search engines.
77

88
## `notFound()`
99

docs/01-app/03-api-reference/04-functions/use-report-web-vitals.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ The `metric` object passed as the hook's argument consists of a number of proper
7272
- `name`: The name of the performance metric. Possible values include names of [Web Vitals](#web-vitals) metrics (TTFB, FCP, LCP, FID, CLS) specific to a web application.
7373
- `delta`: The difference between the current value and the previous value of the metric. The value is typically in milliseconds and represents the change in the metric's value over time.
7474
- `entries`: An array of [Performance Entries](https://developer.mozilla.org/docs/Web/API/PerformanceEntry) associated with the metric. These entries provide detailed information about the performance events related to the metric.
75-
- `navigationType`: Indicates the [type of navigation](https://developer.mozilla.org/docs/Web/API/PerformanceNavigationTiming/type) that triggered the metric collection. Possible values include `"navigate"`, `"reload"`, `"back_forward"`, and `"prerender"`.
75+
- `navigationType`: Indicates the navigation type that triggered metric collection. Values are derived from [PerformanceNavigationTiming.type](https://developer.mozilla.org/docs/Web/API/PerformanceNavigationTiming/type) and may include `"navigate"`, `"reload"`, `"prerender"`, `"back-forward"` (normalized from `"back_forward"`), `"back-forward-cache"` (BFCache restore), and `"restore"` (page restored after discard).
7676
- `rating`: A qualitative rating of the metric value, providing an assessment of the performance. Possible values are `"good"`, `"needs-improvement"`, and `"poor"`. The rating is typically determined by comparing the metric value against predefined thresholds that indicate acceptable or suboptimal performance.
7777
- `value`: The actual value or duration of the performance entry, typically in milliseconds. The value provides a quantitative measure of the performance aspect being tracked by the metric. The source of the value depends on the specific metric being measured and can come from various [Performance API](https://developer.mozilla.org/docs/Web/API/Performance_API)s.
7878

@@ -183,7 +183,7 @@ You can handle all the results of these metrics separately:
183183
```jsx filename="pages/_app.js"
184184
import { useReportWebVitals } from 'next/web-vitals'
185185

186-
function handleCustomMetrics(metrics) {
186+
function handleCustomMetrics(metric) {
187187
switch (metric.name) {
188188
case 'Next.js-hydration':
189189
// handle hydration results
@@ -216,7 +216,7 @@ You can send results to any endpoint to measure and track
216216
real user performance on your site. For example:
217217

218218
```js
219-
function postWebVitals(metrics) {
219+
function postWebVitals(metric) {
220220
const body = JSON.stringify(metric)
221221
const url = 'https://example.com/analytics'
222222

0 commit comments

Comments
 (0)