-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update docs for revalidatePath fix (#55083)
This updates docs for the fixes landed in #53321 related to `revalidatePath`. Fixes: #49387 --------- Co-authored-by: Lee Robinson <me@leerob.io>
- Loading branch information
Showing
7 changed files
with
99 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 20 additions & 5 deletions
25
packages/next/src/server/web/spec-extension/revalidate-path.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,26 @@ | ||
import { revalidateTag } from './revalidate-tag' | ||
import { NEXT_CACHE_IMPLICIT_TAG_ID } from '../../../lib/constants' | ||
import { isDynamicRoute } from '../../../shared/lib/router/utils' | ||
import { | ||
NEXT_CACHE_IMPLICIT_TAG_ID, | ||
NEXT_CACHE_SOFT_TAG_MAX_LENGTH, | ||
} from '../../../lib/constants' | ||
|
||
export function revalidatePath(path: string, type?: 'layout' | 'page') { | ||
path = `${NEXT_CACHE_IMPLICIT_TAG_ID}${path}` | ||
export function revalidatePath(originalPath: string, type?: 'layout' | 'page') { | ||
if (originalPath.length > NEXT_CACHE_SOFT_TAG_MAX_LENGTH) { | ||
console.warn( | ||
`Warning: revalidatePath received "${originalPath}" which exceeded max length of ${NEXT_CACHE_SOFT_TAG_MAX_LENGTH}. See more info here https://nextjs.org/docs/app/api-reference/functions/revalidatePath` | ||
) | ||
return | ||
} | ||
|
||
let normalizedPath = `${NEXT_CACHE_IMPLICIT_TAG_ID}${originalPath}` | ||
|
||
if (type) { | ||
path += `${path.endsWith('/') ? '' : '/'}${type}` | ||
normalizedPath += `${normalizedPath.endsWith('/') ? '' : '/'}${type}` | ||
} else if (isDynamicRoute(originalPath)) { | ||
console.warn( | ||
`Warning: a dynamic page path "${originalPath}" was passed to "revalidatePath" without the "page" argument. This has no affect by default, see more info here https://nextjs.org/docs/app/api-reference/functions/revalidatePath` | ||
) | ||
} | ||
return revalidateTag(path) | ||
return revalidateTag(normalizedPath) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters