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/01-app/02-guides/local-development.mdx
+7-5Lines changed: 7 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -200,7 +200,7 @@ module.exports = {
200
200
201
201
[Learn more about fetch logging](/docs/app/api-reference/config/next-config-js/logging).
202
202
203
-
## Turbopack tracing
203
+
###Turbopack tracing
204
204
205
205
Turbopack tracing is a tool that helps you understand the performance of your application during local development.
206
206
It provides detailed information about the time taken for each module to compile and how they are related.
@@ -214,22 +214,24 @@ It provides detailed information about the time taken for each module to compile
214
214
215
215
1. Navigate around your application or make edits to files to reproduce the problem.
216
216
1. Stop the Next.js development server.
217
-
1. A file called `trace-turbopack` will be available in the `.next` folder.
217
+
1. A file called `trace-turbopack` will be available in the `.next/dev` folder.
218
218
1. You can interpret the file using `npx next internal trace [path-to-file]`:
219
219
220
220
```bash
221
-
npx next internal trace .next/trace-turbopack
221
+
npx next internal trace .next/dev/trace-turbopack
222
222
```
223
223
224
224
On versions where `trace` is not available, the command was named `turbo-trace-server`:
225
225
226
226
```bash
227
-
npx next internal turbo-trace-server .next/trace-turbopack
227
+
npx next internal turbo-trace-server .next/dev/trace-turbopack
228
228
```
229
229
230
230
1. Once the trace server is running you can view the trace at https://trace.nextjs.org/.
231
231
1. By default the trace viewer will aggregate timings, in order to see each individual time you can switch from "Aggregated in order" to "Spans in order" at the top right of the viewer.
232
232
233
-
## Still having problems?
233
+
> **Good to know**: The trace file is place under the development server directory, which defaults to `.next/dev`. This is controllable using the [`isolatedDevBuild`](/docs/app/api-reference/config/next-config-js/isolatedDevBuild) flag in your Next config file.
234
+
235
+
### Still having problems?
234
236
235
237
Share the trace file generated in the [Turbopack Tracing](#turbopack-tracing) section and share it on [GitHub Discussions](https://github.com/vercel/next.js/discussions) or [Discord](https://nextjs.org/discord).
Copy file name to clipboardExpand all lines: docs/01-app/03-api-reference/04-functions/revalidatePath.mdx
+9-6Lines changed: 9 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,12 +49,13 @@ export async function GET() {
49
49
}
50
50
```
51
51
52
-
## Relationship with `revalidateTag`
52
+
## Relationship with `revalidateTag` and `updateTag`
53
53
54
-
`revalidatePath` and [`revalidateTag`](/docs/app/api-reference/functions/revalidateTag) serve different purposes:
54
+
`revalidatePath`, [`revalidateTag`](/docs/app/api-reference/functions/revalidateTag) and [`updateTag`](/docs/app/api-reference/functions/updateTag) serve different purposes:
55
55
56
56
-**`revalidatePath`**: Invalidates a specific page or layout path
57
-
-**`revalidateTag`**: Invalidates data with specific tags across all pages that use those tags
57
+
-**`revalidateTag`**: Marks data with specific tags as **stale**. Applies across all pages that use those tags
58
+
-**`updateTag`**: Expires data with specific tags. Applies across all pages that use those tags
58
59
59
60
When you call `revalidatePath`, only the specified path gets fresh data on the next visit. Other pages that use the same data tags will continue to serve cached data until those specific tags are also revalidated:
60
61
@@ -75,20 +76,22 @@ After calling `revalidatePath('/blog')`:
75
76
-**Page A (/blog)**: Shows fresh data (page re-rendered)
76
77
-**Page B (/dashboard)**: Still shows stale data (cache tag 'posts' not invalidated)
77
78
79
+
Learn about the difference between [`revalidateTag` and `updateTag`](/docs/app/api-reference/functions/updateTag#differences-from-revalidatetag).
80
+
78
81
### Building revalidation utilities
79
82
80
-
`revalidatePath` and `revalidateTag` are complementary primitives that are often used together in utility functions to ensure comprehensive data consistency across your application:
83
+
`revalidatePath` and `updateTag` are complementary primitives that are often used together in utility functions to ensure comprehensive data consistency across your application:
Copy file name to clipboardExpand all lines: docs/01-app/03-api-reference/04-functions/revalidateTag.mdx
+20-4Lines changed: 20 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,8 @@ description: API Reference for the revalidateTag function.
5
5
6
6
`revalidateTag` allows you to invalidate [cached data](/docs/app/guides/caching) on-demand for a specific cache tag.
7
7
8
+
This function is ideal for content where a slight delay in updates is acceptable, such as blog posts, product catalogs, or documentation. Users receive stale content while fresh data loads in the background.
9
+
8
10
## Usage
9
11
10
12
`revalidateTag` can be called in Server Functions and Route Handlers.
@@ -17,7 +19,7 @@ The revalidation behavior depends on whether you provide the second argument:
17
19
18
20
-**With `profile="max"` (recommended)**: The tag entry is marked as stale, and the next time a resource with that tag is visited, it will use stale-while-revalidate semantics. This means the stale content is served while fresh content is fetched in the background.
19
21
-**With a custom cache life profile**: For advanced usage, you can specify any cache life profile that your application has defined, allowing for custom revalidation behaviors tailored to your specific caching requirements.
20
-
-**Without the second argument (deprecated)**: The tag entry is expired immediately, and the next request to that resource will be a blocking revalidate/cache miss. This behavior is now deprecated, and you should either use `profile="max"` or migrate to `updateTag`.
22
+
-**Without the second argument (deprecated)**: The tag entry is expired immediately, and the next request to that resource will be a blocking revalidate/cache miss. This behavior is now deprecated, and you should either use `profile="max"` or migrate to [`updateTag`](/docs/app/api-reference/functions/updateTag).
21
23
22
24
> **Good to know**: When using `profile="max"`, `revalidateTag` marks tagged data as stale, but fresh data is only fetched when pages using that tag are next visited. This means calling `revalidateTag` will not immediately trigger many revalidations at once. The invalidation only happens when any page using that tag is next visited.
-`tag`: A string representing the cache tag associated with the data you want to revalidate. Must not exceed 256 characters. This value is case-sensitive.
31
33
-`profile`: A string that specifies the revalidation behavior. The recommended value is `"max"` which provides stale-while-revalidate semantics. For advanced usage, this can be configured to any cache life profile that your application defines.
32
34
33
-
You can add tags to `fetch` as follows:
35
+
Tags must first be assigned to cached data. You can do this in two ways:
36
+
37
+
- Using the [`next.tags`](/docs/app/guides/caching#fetch-optionsnexttags-and-revalidatetag) option with `fetch` for caching external API requests:
38
+
39
+
```tsx
40
+
fetch(url, { next: { tags: ['posts'] } })
41
+
```
42
+
43
+
- Using [`cacheTag`](/docs/app/api-reference/functions/cacheTag) inside cached functions or components with the `'use cache'` directive:
`revalidateTag` invalidates data with specific tags across all pages that use those tags, while [`revalidatePath`](/docs/app/api-reference/functions/revalidatePath) invalidates specific page or layout paths.
46
62
47
-
> **Good to know**: These functions serve different purposes and may need to be used together for comprehensive data consistency. For detailed examples and considerations, see [Relationship with revalidateTag](/docs/app/api-reference/functions/revalidatePath#relationship-with-revalidatetag).
63
+
> **Good to know**: These functions serve different purposes and may need to be used together for comprehensive data consistency. For detailed examples and considerations, see [relationship with revalidateTag and updateTag](/docs/app/api-reference/functions/revalidatePath#relationship-with-revalidatetag-and-updatetag) for more information.
Copy file name to clipboardExpand all lines: docs/01-app/03-api-reference/04-functions/updateTag.mdx
+37-11Lines changed: 37 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,15 +3,17 @@ title: updateTag
3
3
description: API Reference for the updateTag function.
4
4
---
5
5
6
-
`updateTag` allows you to update [cached data](/docs/app/guides/caching) on-demand for a specific cache tag from within Server Actions. This function is designed specifically for read-your-own-writes scenarios.
6
+
`updateTag` allows you to update [cached data](/docs/app/guides/caching) on-demand for a specific cache tag from within [Server Actions](/docs/app/getting-started/updating-data).
7
+
8
+
This function is designed for **read-your-own-writes** scenarios, where a user makes a change (like creating a post), and the UI immediately shows the change, rather than stale data.
7
9
8
10
## Usage
9
11
10
-
`updateTag` can **only** be called from within Server Actions. It cannot be used in Route Handlers, Client Components, or any other context.
12
+
`updateTag` can **only** be called from within [Server Actions](/docs/app/getting-started/updating-data). It cannot be used in Route Handlers, Client Components, or any other context.
11
13
12
14
If you need to invalidate cache tags in Route Handlers or other contexts, use [`revalidateTag`](/docs/app/api-reference/functions/revalidateTag) instead.
13
15
14
-
> **Good to know**: `updateTag` immediately expires the cached data for the specified tag, causing the next request to that resource to be a blocking revalidate/cache miss. This ensures that Server Actions can immediately see their own writes.
16
+
> **Good to know**: `updateTag` immediately expires the cached data for the specified tag. The next request will wait to fetch fresh data rather than serving stale content from the cache, ensuring users see their changes immediately.
15
17
16
18
## Parameters
17
19
@@ -21,6 +23,26 @@ updateTag(tag: string): void;
21
23
22
24
-`tag`: A string representing the cache tag associated with the data you want to update. Must not exceed 256 characters. This value is case-sensitive.
23
25
26
+
Tags must first be assigned to cached data. You can do this in two ways:
27
+
28
+
- Using the [`next.tags`](/docs/app/guides/caching#fetch-optionsnexttags-and-revalidatetag) option with `fetch` for caching external API requests:
29
+
30
+
```tsx
31
+
fetch(url, { next: { tags: ['posts'] } })
32
+
```
33
+
34
+
- Using [`cacheTag`](/docs/app/api-reference/functions/cacheTag) inside cached functions or components with the `'use cache'` directive:
35
+
36
+
```tsx
37
+
import { cacheTag } from'next/cache'
38
+
39
+
asyncfunction getData() {
40
+
'use cache'
41
+
cacheTag('posts')
42
+
// ...
43
+
}
44
+
```
45
+
24
46
## Returns
25
47
26
48
`updateTag` does not return a value.
@@ -31,12 +53,12 @@ While both `updateTag` and `revalidateTag` invalidate cached data, they serve di
31
53
32
54
-**`updateTag`**:
33
55
- Can only be used in Server Actions
34
-
-Immediately expires the cache entry (blocking revalidate on next visit)
56
+
-Next request waits for fresh data (no stale content served)
35
57
- Designed for read-your-own-writes scenarios
36
58
37
59
-**`revalidateTag`**:
38
60
- Can be used in Server Actions and Route Handlers
39
-
- With `profile="max"` (recommended): Uses stale-while-revalidate semantics
61
+
- With `profile="max"` (recommended): Serves cached data while fetching fresh data in the background (stale-while-revalidate)
40
62
- With custom profile: Can be configured to any cache life profile for advanced usage
41
63
- Without profile: legacy behavior which is equivalent to `updateTag`
42
64
@@ -59,11 +81,13 @@ export async function createPost(formData: FormData) {
59
81
data: { title, content },
60
82
})
61
83
62
-
// Update the cache so the new post is immediately visible
84
+
// Invalidate cache tags so the new post is immediately visible
85
+
// 'posts' tag: affects any page that displays a list of posts
63
86
updateTag('posts')
87
+
// 'post-{id}' tag: affects the individual post detail page
64
88
updateTag(`post-${post.id}`)
65
89
66
-
// Redirect to the new post
90
+
// Redirect to the new post - user will see fresh data, not cached
67
91
redirect(`/posts/${post.id}`)
68
92
}
69
93
```
@@ -83,11 +107,13 @@ export async function createPost(formData) {
83
107
data: { title, content },
84
108
})
85
109
86
-
// Update the cache so the new post is immediately visible
110
+
// Invalidate cache tags so the new post is immediately visible
111
+
// 'posts' tag: affects any page that displays a list of posts
87
112
updateTag('posts')
113
+
// 'post-{id}' tag: affects the individual post detail page
88
114
updateTag(`post-${post.id}`)
89
115
90
-
// Redirect to the new post
116
+
// Redirect to the new post - user will see fresh data, not cached
91
117
redirect(`/posts/${post.id}`)
92
118
}
93
119
```
@@ -98,11 +124,11 @@ export async function createPost(formData) {
98
124
import { updateTag } from'next/cache'
99
125
100
126
exportasyncfunction POST() {
101
-
//❌ This will throw an error
127
+
// This will throw an error
102
128
updateTag('posts')
103
129
// Error: updateTag can only be called from within a Server Action
Copy file name to clipboardExpand all lines: docs/01-app/03-api-reference/08-turbopack.mdx
+9-7Lines changed: 9 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -224,17 +224,19 @@ If you encounter performance or memory issues and want to help the Next.js team
224
224
NEXT_TURBOPACK_TRACING=1 next dev
225
225
```
226
226
227
-
This will produce a `.next/trace-turbopack` file. Include that file when creating a GitHub issue on the [Next.js repo](https://github.com/vercel/next.js) to help us investigate.
227
+
This will produce a `.next/dev/trace-turbopack` file. Include that file when creating a GitHub issue on the [Next.js repo](https://github.com/vercel/next.js) to help us investigate.
228
+
229
+
By default the development server outputs to `.next/dev`. Read more about [isolatedDevBuild](/docs/app/api-reference/config/next-config-js/isolatedDevBuild).
228
230
229
231
## Summary
230
232
231
233
Turbopack is a **Rust-based**, **incremental** bundler designed to make local development and builds fast—especially for large applications. It is integrated into Next.js, offering zero-config CSS, React, and TypeScript support.
0 commit comments