Unverified Commit 7051d255 authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

docs: update `revalidatePath` & fix cache debug logic (#65365)

When revalidating a page that corresponds with a dynamic path and when
using the “type” parameter, eg `revalidatePath(“/dynamic/1”, “page”)`
corresponding with `/dynamic/[id]`, the wrong cache tags would be
checked to determine if a revalidation occurred.

This is because the “derived” cache tags created for a
`/dynamic/[id]/page` are:

- /dynamic/[id]/layout
- /dynamic/[id]/page

Additionally, a tag is added for the current canonical URL, so the final
tag would be:
- /dynamic/1

Thus a fetch on `/dynamic/1` would be tagged with the following:
- /layout
- /dynamic/layout
- /dynamic/[id]/layout
- /dynamic/[id]/page
- /dynamic/1

Calling `revalidatePath(“/dynamic/1”, “page”)` would signal to
revalidate caches tagged `/dynamic/1/page` in the current logic.
However, this tag doesn’t exist given the above, so it would be a no-op
and wouldn't properly re-invoke the fetch.

This updates the docs to explicitly call out that if you are attempting
to revalidate a path that corresponds with a dynamic page, that you
should not provide a "type" argument.

Fixes #62071
Closes NEXT-3302
parent d8e86668
...@@ -19,7 +19,7 @@ revalidatePath(path: string, type?: 'page' | 'layout'): void; ...@@ -19,7 +19,7 @@ revalidatePath(path: string, type?: 'page' | 'layout'): void;
``` ```
- `path`: Either a string representing the filesystem path associated with the data you want to revalidate (for example, `/product/[slug]/page`), or the literal route segment (for example, `/product/123`). Must be less than 1024 characters. This value is case-sensitive. - `path`: Either a string representing the filesystem path associated with the data you want to revalidate (for example, `/product/[slug]/page`), or the literal route segment (for example, `/product/123`). Must be less than 1024 characters. This value is case-sensitive.
- `type`: (optional) `'page'` or `'layout'` string to change the type of path to revalidate. If `path` contains a dynamic segment (for example, `/product/[slug]/page`), this parameter is required. - `type`: (optional) `'page'` or `'layout'` string to change the type of path to revalidate. If `path` contains a dynamic segment (for example, `/product/[slug]/page`), this parameter is required. If path refers to the literal route segment, e.g., `/product/1` for a dynamic page (e.g., `/product/[slug]/page`), you should not provide `type`.
## Returns ## Returns
......
...@@ -55,7 +55,8 @@ export default class FileSystemCache implements CacheHandler { ...@@ -55,7 +55,8 @@ export default class FileSystemCache implements CacheHandler {
this.isAppPPREnabled = ctx.isAppPPREnabled this.isAppPPREnabled = ctx.isAppPPREnabled
this.debug = !!process.env.NEXT_PRIVATE_DEBUG_CACHE this.debug = !!process.env.NEXT_PRIVATE_DEBUG_CACHE
if (ctx.maxMemoryCacheSize && !memoryCache) { if (ctx.maxMemoryCacheSize) {
if (!memoryCache) {
if (this.debug) { if (this.debug) {
console.log('using memory store for fetch cache') console.log('using memory store for fetch cache')
} }
...@@ -80,6 +81,7 @@ export default class FileSystemCache implements CacheHandler { ...@@ -80,6 +81,7 @@ export default class FileSystemCache implements CacheHandler {
) )
}, },
}) })
}
} else if (this.debug) { } else if (this.debug) {
console.log('not using memory store for fetch cache') console.log('not using memory store for fetch cache')
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment