Skip to content

Commit 46709a2

Browse files
authored
docs: update revalidatePath, revalidateTag docs to be more consistent + highlight res.revalidate case (#82479)
- uses invalidate instead of revalidate to make more explicit the revalidatePath, revalidateTag behavior - highlights that eager revalidation can still happen with the pages router method <!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation - Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide ### Adding or Updating Examples - The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md - Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Closes NEXT- Fixes # -->
1 parent e590df4 commit 46709a2

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

docs/01-app/02-guides/incremental-static-regeneration.mdx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,17 +281,19 @@ We recommend setting a high revalidation time. For instance, 1 hour instead of 1
281281

282282
### On-demand revalidation with `revalidatePath`
283283

284-
For a more precise method of revalidation, invalidate pages on-demand with the `revalidatePath` function.
284+
For a more precise method of revalidation, invalidate cached pages on-demand with the `revalidatePath` function.
285285

286-
For example, this Server Action would get called after adding a new post. Regardless of how you retrieve your data in your Server Component, either using `fetch` or connecting to a database, this will immediately clear the cache for the entire route. Unlike time-based revalidation, the next request after on-demand revalidation won't return stale data but will serve the updated version right away and cache it for subsequent requests.
286+
For example, this Server Action would get called after adding a new post. Regardless of how you retrieve your data in your Server Component, either using `fetch` or connecting to a database, this will invalidate the cache for the entire route. The next request to that route will trigger regeneration and serve fresh data, which will then be cached for subsequent requests.
287+
288+
> **Note:** `revalidatePath` invalidates the cache entries but regeneration happens on the next request. If you want to eagerly regenerate the cache entry immediately instead of waiting for the next request, you can use the Pages router [`res.revalidate`](docs/pages/guides/incremental-static-regeneration#on-demand-validation-with-resrevalidate) method. We're working on adding new methods to provide eager regeneration capabilities for the App Router.
287289
288290
```ts filename="app/actions.ts" switcher
289291
'use server'
290292

291293
import { revalidatePath } from 'next/cache'
292294

293295
export async function createPost() {
294-
// Invalidate the /posts route in the cache
296+
// Invalidate the cache for the /posts route
295297
revalidatePath('/posts')
296298
}
297299
```
@@ -302,7 +304,7 @@ export async function createPost() {
302304
import { revalidatePath } from 'next/cache'
303305

304306
export async function createPost() {
305-
// Invalidate the /posts route in the cache
307+
// Invalidate the cache for the /posts route
306308
revalidatePath('/posts')
307309
}
308310
```
@@ -379,7 +381,7 @@ You can then use `revalidateTag` in a [Server Actions](/docs/app/getting-started
379381
import { revalidateTag } from 'next/cache'
380382

381383
export async function createPost() {
382-
// Invalidate all data tagged with 'posts' in the cache
384+
// Invalidate all data tagged with 'posts'
383385
revalidateTag('posts')
384386
}
385387
```
@@ -390,7 +392,7 @@ export async function createPost() {
390392
import { revalidateTag } from 'next/cache'
391393

392394
export async function createPost() {
393-
// Invalidate all data tagged with 'posts' in the cache
395+
// Invalidate all data tagged with 'posts'
394396
revalidateTag('posts')
395397
}
396398
```

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: revalidatePath
33
description: API Reference for the revalidatePath function.
44
---
55

6-
`revalidatePath` allows you to purge [cached data](/docs/app/guides/caching) on-demand for a specific path.
6+
`revalidatePath` allows you to invalidate [cached data](/docs/app/guides/caching) on-demand for a specific path.
77

88
## Usage
99

@@ -29,13 +29,13 @@ revalidatePath(path: string, type?: 'page' | 'layout'): void;
2929

3030
`revalidatePath` does not return a value.
3131

32-
## What can be revalidated
32+
## What can be invalidated
3333

3434
The path parameter can point to pages, layouts, or route handlers:
3535

36-
- **Pages**: Revalidates the specific page
37-
- **Layouts**: Revalidates the layout and all pages beneath it
38-
- **Route Handlers**: Revalidates Data Cache entries accessed within route handlers. For example `revalidatePath("/api/data")` revalidates this GET handler:
36+
- **Pages**: Invalidates the specific page
37+
- **Layouts**: Invalidates the layout and all pages beneath it
38+
- **Route Handlers**: Invalidates Data Cache entries accessed within route handlers. For example `revalidatePath("/api/data")` invalidates this GET handler:
3939

4040
```ts filename="app/api/data/route.ts"
4141
export async function GET() {
@@ -51,8 +51,8 @@ export async function GET() {
5151

5252
`revalidatePath` and [`revalidateTag`](/docs/app/api-reference/functions/revalidateTag) serve different purposes:
5353

54-
- **`revalidatePath`**: Revalidates a specific page or layout path
55-
- **`revalidateTag`**: Revalidates data with specific tags across all pages that use those tags
54+
- **`revalidatePath`**: Invalidates a specific page or layout path
55+
- **`revalidateTag`**: Invalidates data with specific tags across all pages that use those tags
5656

5757
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:
5858

@@ -101,7 +101,7 @@ import { revalidatePath } from 'next/cache'
101101
revalidatePath('/blog/post-1')
102102
```
103103

104-
This will revalidate one specific URL on the next page visit.
104+
This will invalidate one specific URL for revalidation on the next page visit.
105105

106106
### Revalidating a Page path
107107

@@ -112,7 +112,7 @@ revalidatePath('/blog/[slug]', 'page')
112112
revalidatePath('/(main)/blog/[slug]', 'page')
113113
```
114114

115-
This will revalidate any URL that matches the provided `page` file on the next page visit. This will _not_ invalidate pages beneath the specific page. For example, `/blog/[slug]` won't invalidate `/blog/[slug]/[author]`.
115+
This will invalidate any URL that matches the provided `page` file for revalidation on the next page visit. This will _not_ invalidate pages beneath the specific page. For example, `/blog/[slug]` won't invalidate `/blog/[slug]/[author]`.
116116

117117
### Revalidating a Layout path
118118

@@ -123,7 +123,7 @@ revalidatePath('/blog/[slug]', 'layout')
123123
revalidatePath('/(main)/post/[slug]', 'layout')
124124
```
125125

126-
This will revalidate any URL that matches the provided `layout` file on the next page visit. This will cause pages beneath with the same layout to revalidate on the next visit. For example, in the above case, `/blog/[slug]/[another]` would also revalidate on the next visit.
126+
This will invalidate any URL that matches the provided `layout` file for revalidation on the next page visit. This will cause pages beneath with the same layout to be invalidated and revalidated on the next visit. For example, in the above case, `/blog/[slug]/[another]` would also be invalidated and revalidated on the next visit.
127127

128128
### Revalidating all data
129129

@@ -133,7 +133,7 @@ import { revalidatePath } from 'next/cache'
133133
revalidatePath('/', 'layout')
134134
```
135135

136-
This will purge the Client-side Router Cache, and revalidate the Data Cache on the next page visit.
136+
This will purge the Client-side Router Cache, and invalidate the Data Cache for revalidation on the next page visit.
137137

138138
### Server Function
139139

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: revalidateTag
33
description: API Reference for the revalidateTag function.
44
---
55

6-
`revalidateTag` allows you to purge [cached data](/docs/app/guides/caching) on-demand for a specific cache tag.
6+
`revalidateTag` allows you to invalidate [cached data](/docs/app/guides/caching) on-demand for a specific cache tag.
77

88
## Usage
99

@@ -33,7 +33,7 @@ fetch(url, { next: { tags: [...] } });
3333

3434
## Relationship with `revalidatePath`
3535

36-
`revalidateTag` revalidates data with specific tags across all pages that use those tags, while [`revalidatePath`](/docs/app/api-reference/functions/revalidatePath) revalidates specific page or layout paths.
36+
`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.
3737

3838
> **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).
3939

0 commit comments

Comments
 (0)