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,31 +55,33 @@ export default class FileSystemCache implements CacheHandler { ...@@ -55,31 +55,33 @@ 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 (this.debug) { if (!memoryCache) {
console.log('using memory store for fetch cache') if (this.debug) {
} console.log('using memory store for fetch cache')
}
memoryCache = new LRUCache({ memoryCache = new LRUCache({
max: ctx.maxMemoryCacheSize, max: ctx.maxMemoryCacheSize,
length({ value }) { length({ value }) {
if (!value) { if (!value) {
return 25 return 25
} else if (value.kind === 'REDIRECT') { } else if (value.kind === 'REDIRECT') {
return JSON.stringify(value.props).length return JSON.stringify(value.props).length
} else if (value.kind === 'IMAGE') { } else if (value.kind === 'IMAGE') {
throw new Error('invariant image should not be incremental-cache') throw new Error('invariant image should not be incremental-cache')
} else if (value.kind === 'FETCH') { } else if (value.kind === 'FETCH') {
return JSON.stringify(value.data || '').length return JSON.stringify(value.data || '').length
} else if (value.kind === 'ROUTE') { } else if (value.kind === 'ROUTE') {
return value.body.length return value.body.length
} }
// rough estimate of size of cache value // rough estimate of size of cache value
return ( return (
value.html.length + (JSON.stringify(value.pageData)?.length || 0) value.html.length + (JSON.stringify(value.pageData)?.length || 0)
) )
}, },
}) })
}
} 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