You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Back porting docs updates into 16-1 (canary now contains changes that
shouldn't show in 16.1)
---------
Co-authored-by: Eng Zer Jun <engzerjun@gmail.com>
Co-authored-by: Rich Haines <hello@richardhaines.dev>
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
Co-authored-by: Delba de Oliveira <32464864+delbaoliveira@users.noreply.github.com>
Co-authored-by: Luke Sandberg <lukesandberg@users.noreply.github.com>
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Co-authored-by: Jiachi Liu <inbox@huozhi.im>
Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Copy file name to clipboardExpand all lines: docs/01-app/01-getting-started/04-linking-and-navigating.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -328,7 +328,7 @@ function HoverPrefetchLink({ href, children }) {
328
328
329
329
React mitigates this with Selective Hydration and you can further improve this by:
330
330
331
-
- Using the [`@next/bundle-analyzer`](/docs/app/guides/package-bundling#analyzing-javascript-bundles) plugin to identify and reduce bundle size by removing large dependencies.
331
+
- Using the [`@next/bundle-analyzer`](/docs/app/guides/package-bundling#nextbundle-analyzer-for-webpack) plugin to identify and reduce bundle size by removing large dependencies.
332
332
- Moving logic from the client to the server where possible. See the [Server and Client Components](/docs/app/getting-started/server-and-client-components) docs for guidance.
Copy file name to clipboardExpand all lines: docs/01-app/01-getting-started/05-server-and-client-components.mdx
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,7 @@ Use **Server Components** when you need:
32
32
33
33
For example, the `<Page>` component is a Server Component that fetches data about a post, and passes it as props to the `<LikeButton>` which handles client-side interactivity.
Copy file name to clipboardExpand all lines: docs/01-app/01-getting-started/06-cache-components.mdx
+11-6Lines changed: 11 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -86,7 +86,7 @@ export default async function Page() {
86
86
}
87
87
```
88
88
89
-
> **Good to know**: You can verify that a route was fully prerendered by checking the build output summary. Alternatively see what content was added to the static shell of any page by viewing the page source in your browser.
89
+
> **Good to know**: You can verify that a route was fully prerendered by checking the build output summary. Alternatively, see what content was added to the static shell of any page by viewing the page source in your browser.
90
90
91
91
## Defer rendering to request time
92
92
@@ -102,12 +102,11 @@ External systems provide content asynchronously, which often takes an unpredicta
102
102
103
103
In general, when you need the latest data from the source on each request (like real-time feeds or personalized content), defer rendering by providing fallback UI with a Suspense boundary.
104
104
105
-
For example the `DynamicContent` component below uses multiple operations that are not automatically prerendered.
105
+
For example, the `DynamicContent` component below uses multiple operations that are not automatically prerendered.
106
106
107
107
```tsx filename="page.tsx"
108
108
import { Suspense } from'react'
109
109
importfsfrom'node:fs/promises'
110
-
import { setTimeout } from'node:timers/promises'
111
110
112
111
asyncfunction DynamicContent() {
113
112
// Network request
@@ -120,7 +119,7 @@ async function DynamicContent() {
120
119
const file =awaitfs.readFile('..', 'utf-8')
121
120
122
121
// Simulating external system delay
123
-
awaitsetTimeout(100) // from 'node:timers/promises'
@@ -174,7 +173,7 @@ async function RuntimeData({ searchParams }) {
174
173
}
175
174
```
176
175
177
-
To use the `RuntimeData` component in, wrap it in a `<Suspense>` boundary:
176
+
To use the `RuntimeData` component, wrap it in a `<Suspense>` boundary:
178
177
179
178
```tsx filename="page.tsx"
180
179
exportdefaultasyncfunction Page(props) {
@@ -504,6 +503,12 @@ During prerendering the header (static) and the blog posts fetched from the API
504
503
505
504
When a user visits the page, they instantly see this prerendered shell with the header and blog posts. Only the personalized preferences need to stream in at request time since they depend on the user's cookies. This ensures fast initial page loads while still providing personalized content.
506
505
506
+
## Metadata and Viewport
507
+
508
+
`generateMetadata` and `generateViewport` are part of rendering your page or layout. During prerendering, their access to runtime data or uncached dynamic data is tracked separately from the rest of the page.
509
+
510
+
If a page or layout is prerenderable but only metadata or viewport accesses uncached dynamic data or runtime data, Next.js requires an explicit choice: cache the data if possible, or signal that deferred rendering is intentional. See [Metadata with Cache Components](/docs/app/api-reference/functions/generate-metadata#with-cache-components) and [Viewport with Cache Components](/docs/app/api-reference/functions/generate-viewport#with-cache-components) for how to handle this.
511
+
507
512
## Enabling Cache Components
508
513
509
514
You can enable Cache Components (which includes PPR) by adding the [`cacheComponents`](/docs/app/api-reference/config/next-config-js/cacheComponents) option to your Next config file:
@@ -569,7 +574,7 @@ export default function Page() {
569
574
570
575
### `dynamic = "force-static"`
571
576
572
-
Start by removing it. When unhandled dynamic or runtime data access is detected during development and built time, Next.js raises an error. Otherwise, the [prerendering](#automatically-prerendered-content) step automatically extracts the static HTML shell.
577
+
Start by removing it. When unhandled dynamic or runtime data access is detected during development and build time, Next.js raises an error. Otherwise, the [prerendering](#automatically-prerendered-content) step automatically extracts the static HTML shell.
573
578
574
579
For dynamic data access, add [`use cache`](#using-use-cache) as close to the data access as possible with a long [`cacheLife`](/docs/app/api-reference/functions/cacheLife) like `'max'` to maintain cached behavior. If needed, add it at the top of the page or layout.
Copy file name to clipboardExpand all lines: docs/01-app/01-getting-started/13-fonts.mdx
+214Lines changed: 214 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,8 @@ The [`next/font`](/docs/app/api-reference/components/font) module automatically
12
12
13
13
It includes **built-in self-hosting** for any font file. This means you can optimally load web fonts with no layout shift.
14
14
15
+
<AppOnly>
16
+
15
17
To start using `next/font`, import it from [`next/font/local`](#local-fonts) or [`next/font/google`](#google-fonts), call it as a function with the appropriate options, and set the `className` of the element you want to apply the font to. For example:
@@ -48,12 +50,99 @@ export default function Layout({ children }) {
48
50
49
51
Fonts are scoped to the component they're used in. To apply a font to your entire application, add it to the [Root Layout](/docs/app/api-reference/file-conventions/layout#root-layout).
50
52
53
+
</AppOnly>
54
+
55
+
<PagesOnly>
56
+
57
+
To start using `next/font`, import it from [`next/font/local`](#local-fonts) or [`next/font/google`](#google-fonts), call it as a function with the appropriate options, and set the `className` of the element you want to apply the font to. For example, you can apply fonts globally in your [Custom App](/docs/pages/building-your-application/routing/custom-app) (`pages/_app`):
If you want to apply the font to the `<html>` element, you can use a [Custom Document](/docs/pages/building-your-application/routing/custom-document) (`pages/_document`):
You can automatically self-host any Google Font. Fonts are included stored as static assets and served from the same domain as your deployment, meaning no requests are sent to Google by the browser when the user visits your site.
54
141
55
142
To start using a Google Font, import your chosen font from `next/font/google`:
56
143
144
+
<AppOnly>
145
+
57
146
```tsx filename="app/layout.tsx" switcher
58
147
import { Geist } from'next/font/google'
59
148
@@ -90,8 +179,49 @@ export default function RootLayout({ children }) {
We recommend using [variable fonts](https://fonts.google.com/variablefonts) for the best performance and flexibility. But if you can't use a variable font, you will need to specify a weight:
To use a local font, import your font from `next/font/local` and specify the [`src`](/docs/app/api-reference/components/font#src) of your local font file. Fonts can be stored in the [`public`](/docs/app/api-reference/file-conventions/public-folder) folder or co-located inside the `app` folder. For example:
136
309
137
310
```tsx filename="app/layout.tsx" switcher
@@ -170,6 +343,47 @@ export default function RootLayout({ children }) {
170
343
}
171
344
```
172
345
346
+
</AppOnly>
347
+
348
+
<PagesOnly>
349
+
350
+
To use a local font, import your font from `next/font/local` and specify the [`src`](/docs/pages/api-reference/components/font#src) of your local font file. Fonts can be stored in the [`public`](/docs/pages/api-reference/file-conventions/public-folder) folder or inside the `pages` folder. For example:
Copy file name to clipboardExpand all lines: docs/01-app/01-getting-started/16-proxy.mdx
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,7 +52,6 @@ export function proxy(request: NextRequest) {
52
52
// Alternatively, you can use a default export:
53
53
// export default function proxy(request: NextRequest) { ... }
54
54
55
-
// See "Matching Paths" below to learn more
56
55
exportconst config = {
57
56
matcher: '/about/:path*',
58
57
}
@@ -69,10 +68,11 @@ export function proxy(request) {
69
68
// Alternatively, you can use a default export:
70
69
// export default function proxy(request) { ... }
71
70
72
-
// See "Matching Paths" below to learn more
73
71
exportconstconfig= {
74
72
matcher:'/about/:path*',
75
73
}
76
74
```
77
75
76
+
The `matcher` config allows you to filter Proxy to run on specific paths. See the [Matcher](/docs/app/api-reference/file-conventions/proxy#matcher) documentation for more details on path matching.
77
+
78
78
Read more about [using `proxy`](/docs/app/guides/backend-for-frontend#proxy), or refer to the `proxy`[API reference](/docs/app/api-reference/file-conventions/proxy).
Copy file name to clipboardExpand all lines: docs/01-app/02-guides/content-security-policy.mdx
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -415,9 +415,11 @@ Consider nonces when:
415
415
For applications that do not require nonces, you can set the CSP header directly in your [`next.config.js`](/docs/app/api-reference/config/next-config-js) file:
0 commit comments