-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update tags handling during server action redirect (#49227)
Updates the tag handling during a server action direct to pass through the revalidated tags for immediate revalidation as discussed. x-ref: [slack thread](https://vercel.slack.com/archives/C042LHPJ1NX/p1683218335368759)
- Loading branch information
Showing
8 changed files
with
85 additions
and
27 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
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export const getDerivedTags = (tags: string[]): string[] => { | ||
const derivedTags: string[] = ['/'] | ||
|
||
for (const tag of tags || []) { | ||
if (tag.startsWith('/')) { | ||
const pathnameParts = tag.split('/') | ||
|
||
// we automatically add the current path segments as tags | ||
// for revalidatePath handling | ||
for (let i = 1; i < pathnameParts.length + 1; i++) { | ||
const curPathname = pathnameParts.slice(0, i).join('/') | ||
|
||
if (curPathname) { | ||
derivedTags.push(curPathname) | ||
|
||
if (!derivedTags.includes(curPathname)) { | ||
derivedTags.push(curPathname) | ||
} | ||
} | ||
} | ||
} else if (!derivedTags.includes(tag)) { | ||
derivedTags.push(tag) | ||
} | ||
} | ||
return derivedTags | ||
} |
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