Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
100 additions
and
17 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}.` | ||
) | ||
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` | ||
) | ||
} | ||
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