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
Copy file name to clipboardExpand all lines: docs/02-app/01-building-your-application/02-data-fetching/01-fetching-caching-and-revalidating.mdx
+15-88Lines changed: 15 additions & 88 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ There are four ways you can fetch data:
17
17
18
18
Next.js extends the native [`fetch` Web API](https://developer.mozilla.org/docs/Web/API/Fetch_API) to allow you to configure the [caching](#caching-data) and [revalidating](#revalidating-data) behavior for each fetch request on the server. React extends `fetch` to automatically [memoize](/docs/app/building-your-application/data-fetching/patterns#fetching-data-where-its-needed) fetch requests while rendering a React component tree.
19
19
20
-
You can use `fetch` with [`async`/`await` in Server Components](https://github.com/acdlite/rfcs/blob/first-class-promises/text/0000-first-class-support-for-promises.md), in [Route Handlers](/docs/app/building-your-application/routing/route-handlers), and in [Server Actions](/docs/app/building-your-application/data-fetching/forms-and-mutations).
20
+
You can use `fetch` with `async`/`await` in Server Components, in [Route Handlers](/docs/app/building-your-application/routing/route-handlers), and in [Server Actions](/docs/app/building-your-application/data-fetching/forms-and-mutations).
21
21
22
22
For example:
23
23
@@ -117,7 +117,7 @@ Learn more about [time-based revalidation](/docs/app/building-your-application/c
117
117
118
118
#### On-demand Revalidation
119
119
120
-
Data can be revalidated on-demand by path ([`revalidatePath`](/docs/app/api-reference/functions/revalidatePath)) or by cache tag ([`revalidateTag`](/docs/app/api-reference/functions/revalidateTag)) inside a Route Handler or a Server Action.
120
+
Data can be revalidated on-demand by path ([`revalidatePath`](/docs/app/api-reference/functions/revalidatePath)) or by cache tag ([`revalidateTag`](/docs/app/api-reference/functions/revalidateTag)) inside a [Server Action](/docs/app/building-your-application/data-fetching/forms-and-mutations) or [Route Handler](/docs/app/building-your-application/routing/route-handlers).
121
121
122
122
Next.js has a cache tagging system for invalidating `fetch` requests across routes.
123
123
@@ -142,89 +142,25 @@ export default async function Page() {
142
142
}
143
143
```
144
144
145
-
If using a Route Handler, you should create a secret token only known by your Next.js app. This secret will be used to prevent unauthorized revalidation attempts. For example, you can access the route (either manually or with a webhook) with the following URL structure:
145
+
You can then revalidate this `fetch` call tagged with `collection`by calling `revalidateTag` in a Server Action:
@@ -260,24 +196,15 @@ View all the available `cache` options in the [`fetch` API reference](/docs/app/
260
196
261
197
If you have multiple `fetch` requests in a route segment (e.g. a Layout or Page), you can configure the caching behavior of all data requests in the segment using the [Segment Config Options](/docs/app/api-reference/file-conventions/route-segment-config).
262
198
263
-
For example, using `const dynamic = 'force-dynamic'` will cause all data to be fetched at request time, and the segment to be rendered dynamically.
264
-
265
-
```js filename="layout.js | page.js"
266
-
// Add
267
-
exportconstdynamic='force-dynamic'
268
-
```
269
-
270
-
There's an extensive list of Segment Config options, giving you fine-grained control of static and dynamic behavior of a route segment. See the [API reference](/docs/app/api-reference/file-conventions/route-segment-config) for more.
199
+
However, we recommend configuring the caching behavior of each `fetch` request individually. This gives you more granular control over the caching behavior.
271
200
272
201
## Fetching data on the Server with third-party libraries
273
202
274
203
In cases where you're using a third-party library that doesn't support or expose `fetch` (for example, a database, CMS, or ORM client), you can configure the caching and revalidating behavior of those requests using the [Route Segment Config Option](/docs/app/api-reference/file-conventions/route-segment-config) and React's `cache` function.
275
204
276
205
Whether the data is cached or not will depend on whether the route segment is [statically or dynamically rendered](/docs/app/building-your-application/rendering/server-components#server-rendering-strategies). If the segment is static (default), the output of the request will be cached and revalidated as part of the route segment. If the segment is dynamic, the output of the request will _not_ be cached and will be re-fetched on every request when the segment is rendered.
277
206
278
-
> **Good to know:**
279
-
>
280
-
> Next.js is working on an API, `unstable_cache`, for configuring the caching and revalidating behavior of individual third-party requests.
207
+
You can also use the experimental [`unstable_cache` API](/docs/app/api-reference/functions/unstable_cache).
281
208
282
209
### Example
283
210
@@ -370,4 +297,4 @@ You can also fetch data on the client using a third-party library such as [SWR](
370
297
371
298
> **Future APIs**:
372
299
>
373
-
> `use` is a React function that **accepts and handles a promise** returned by a function. Wrapping `fetch` in `use` is currently **not** recommended in Client Components and may trigger multiple re-renders. Learn more about `use` in the [React RFC](https://github.com/acdlite/rfcs/blob/first-class-promises/text/0000-first-class-support-for-promises.md#usepromise).
300
+
> `use` is a React function that **accepts and handles a promise** returned by a function. Wrapping `fetch` in `use` is currently **not** recommended in Client Components and may trigger multiple re-renders. Learn more about `use` in the [React docs](https://react.dev/reference/react/use).
Copy file name to clipboardExpand all lines: docs/02-app/01-building-your-application/02-data-fetching/03-forms-and-mutations.mdx
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -360,7 +360,7 @@ export default async function submit(formData) {
360
360
361
361
<AppOnly>
362
362
363
-
Use the `useFormStatus` hook to show a loading state when a form is submitting on the server. The `useFormStatus` hook can only be used as a child of a `form` element using a Server Action.
363
+
Use the [`useFormStatus`](https://react.dev/reference/react-dom/hooks/useFormStatus) hook to show a loading state when a form is submitting on the server. The `useFormStatus` hook can only be used as a child of a `form` element using a Server Action.
364
364
365
365
For example, the following submit button:
366
366
@@ -731,7 +731,7 @@ Use `useOptimistic` to optimistically update the UI before the Server Action fin
Copy file name to clipboardExpand all lines: docs/02-app/01-building-your-application/03-rendering/02-client-components.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
@@ -103,4 +103,4 @@ This means the Client Component JavaScript bundle is downloaded and parsed. Once
103
103
104
104
Sometimes, after you've declared the `"use client"` boundary, you may want to go back to the server environment. For example, you may want to reduce the client bundle size, fetch data on the server, or use an API that is only available on the server.
105
105
106
-
You can keep code on the server even though it's theoretically nested inside Client Components by interleaving Client and Server Components and Server Actions. See the [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns) page for more information.
106
+
You can keep code on the server even though it's theoretically nested inside Client Components by interleaving Client and Server Components and [Server Actions](/docs/app/building-your-application/data-fetching/forms-and-mutations). See the [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns) page for more information.
@@ -480,7 +480,7 @@ See the [`fetch` API reference](/docs/app/api-reference/functions/fetch) for mor
480
480
481
481
Next.js has a cache tagging system for fine-grained data caching and revalidation.
482
482
483
-
1. When using `fetch` or `unstable_cache`, you have the option to tag cache entries with one or more tags.
483
+
1. When using `fetch` or [`unstable_cache`](/docs/app/api-reference/functions/unstable_cache), you have the option to tag cache entries with one or more tags.
484
484
2. Then, you can call `revalidateTag` to purge the cache entries associated with that tag.
485
485
486
486
For example, you can set a tag when fetching data:
`unstable_cache` is an experimental API for adding values to the Data Cache when the `fetch` API is not suitable. For example, when using database clients, CMS clients, or GraphQL.
584
-
585
-
```jsx
586
-
import { unstable_cache } from'next/cache'
587
-
588
-
exportdefaultasyncfunctionPage() {
589
-
constcachedData=awaitunstable_cache(
590
-
async () => {
591
-
constdata=awaitdb.query('...')
592
-
return data
593
-
},
594
-
['cache-key'],
595
-
{
596
-
tags: ['a', 'b', 'c'],
597
-
revalidate:10,
598
-
}
599
-
)()
600
-
}
601
-
```
602
-
603
-
> **Warning**: This API is being developed, and we do not recommend using it in production. It's listed here to show the future direction of the Data Cache.
Copy file name to clipboardExpand all lines: docs/02-app/01-building-your-application/06-optimizing/04-metadata.mdx
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,7 @@ related:
6
6
links:
7
7
- app/api-reference/functions/generate-metadata
8
8
- app/api-reference/file-conventions/metadata
9
+
- app/api-reference/functions/generate-viewport
9
10
---
10
11
11
12
Next.js has a Metadata API that can be used to define your application metadata (e.g. `meta` and `link` tags inside your HTML `head` element) for improved SEO and web shareability.
Copy file name to clipboardExpand all lines: docs/02-app/01-building-your-application/06-optimizing/index.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
@@ -24,7 +24,7 @@ Metadata helps search engines understand your content better (which can result i
24
24
25
25
The Metadata API in Next.js allows you to modify the `<head>` element of a page. You can configure metadata in two ways:
26
26
27
-
-**Config-based Metadata**: Export a static metadata object or a dynamic generateMetadata function in a `layout.js` or `page.js` file.
27
+
-**Config-based Metadata**: Export a [static `metadata` object](/docs/app/api-reference/functions/generate-metadata#metadata-object) or a dynamic [`generateMetadata` function](/docs/app/api-reference/functions/generate-metadata#generatemetadata-function) in a `layout.js` or `page.js` file.
28
28
-**File-based Metadata**: Add static or dynamically generated special files to route segments.
29
29
30
30
Additionally, you can create dynamic Open Graph Images using JSX and CSS with [imageResponse](/docs/app/api-reference/functions/image-response) constructor.
With a static export, Next.js can be deployed and hosted on any web server that can serve HTML/CSS/JS static assets.
325
325
326
-
When running `next build`, Next.js generates the static export into the `out` folder. Using `next export` is no longer needed. For example, let's say you have the following routes:
326
+
When running `next build`, Next.js generates the static export into the `out` folder. For example, let's say you have the following routes:
Copy file name to clipboardExpand all lines: docs/02-app/01-building-your-application/09-upgrading/01-codemods.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
@@ -34,15 +34,15 @@ Replacing `<transform>` and `<path>` with appropriate values.
34
34
npx @next/codemod@latest next-og-import.
35
35
```
36
36
37
-
This codemo migrates the import path of `ImageResponse`from `'next/server'` to `'next/og'`
37
+
This codemod moves transforms imports from `next/server` to `next/og` for usage of [Dynamic OG Image Generation](/docs/app/building-your-application/optimizing/metadata#dynamic-image-generation).
0 commit comments