-
Notifications
You must be signed in to change notification settings - Fork 28.6k
Fix revalidateTag()
behaviour when invoked in server components
#70446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
186b3ff
revalidate tags in case of rsc payload response from server
abhi12299 035a389
add checks for revalidatedTags along with pendingRevalidates
abhi12299 301575a
add tests
abhi12299 7eb14d7
undo formatting
abhi12299 7bc0b9d
add check for pendingRevalidates in generateDynamicFlightRenderResult
abhi12299 2f55634
fix search params typing in test
abhi12299 9ca9553
Merge branch 'canary' into fix-revalidatetag-rsc
ijjk 02cd740
add revalidate: false in test to have predictable behaviour during te…
abhi12299 2fb6ca3
Merge branch 'canary' into fix-revalidatetag-rsc
abhi12299 7f22377
fix flakey assertion
ijjk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
17 changes: 17 additions & 0 deletions
17
test/e2e/app-dir/revalidatetag-rsc/app/RevalidateViaForm.tsx
This file contains hidden or 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,17 @@ | ||
'use client' | ||
|
||
import { revalidate } from './actions/revalidate' | ||
|
||
export default function RevalidateViaForm({ tag }: { tag: string }) { | ||
const handleRevalidate = async () => { | ||
await revalidate(tag) | ||
} | ||
|
||
return ( | ||
<form action={handleRevalidate}> | ||
<button type="submit" id="submit-form" className="underline"> | ||
Revalidate via form | ||
</button> | ||
</form> | ||
) | ||
} |
11 changes: 11 additions & 0 deletions
11
test/e2e/app-dir/revalidatetag-rsc/app/actions/revalidate.ts
This file contains hidden or 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,11 @@ | ||
'use server' | ||
|
||
import { revalidateTag } from 'next/cache' | ||
|
||
export const revalidate = async ( | ||
tag: string | ||
): Promise<{ revalidated: boolean }> => { | ||
revalidateTag(tag) | ||
|
||
return { revalidated: true } | ||
} |
This file contains hidden or 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,9 @@ | ||
import { ReactNode } from 'react' | ||
|
||
export default function Root({ children }: { children: ReactNode }) { | ||
return ( | ||
<html> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
This file contains hidden or 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,24 @@ | ||
import RevalidateViaForm from './RevalidateViaForm' | ||
import Link from 'next/link' | ||
|
||
export default async function Page() { | ||
const data = await fetch( | ||
'https://next-data-api-endpoint.vercel.app/api/random', | ||
{ | ||
next: { | ||
tags: ['data'], | ||
revalidate: false, | ||
}, | ||
} | ||
).then((res) => res.text()) | ||
|
||
return ( | ||
<div> | ||
<span id="data">{data}</span> | ||
<RevalidateViaForm tag="data" /> | ||
<Link href="/revalidate_via_page?tag=data" id="revalidate-via-page"> | ||
Revalidate via page | ||
</Link> | ||
</div> | ||
) | ||
} |
24 changes: 24 additions & 0 deletions
24
test/e2e/app-dir/revalidatetag-rsc/app/revalidate_via_page/page.tsx
This file contains hidden or 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,24 @@ | ||
'use server' | ||
|
||
import Link from 'next/link' | ||
import { revalidateTag } from 'next/cache' | ||
|
||
const RevalidateViaPage = async ({ | ||
searchParams, | ||
}: { | ||
searchParams: Promise<{ tag: string }> | ||
}) => { | ||
const { tag } = await searchParams | ||
revalidateTag(tag) | ||
|
||
return ( | ||
<div className="flex flex-col items-center justify-center h-screen"> | ||
<pre>Tag [{tag}] has been revalidated</pre> | ||
<Link href="/" id="home"> | ||
To Home | ||
</Link> | ||
</div> | ||
) | ||
} | ||
|
||
export default RevalidateViaPage |
This file contains hidden or 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,6 @@ | ||
/** | ||
* @type {import('next').NextConfig} | ||
*/ | ||
const nextConfig = {} | ||
|
||
module.exports = nextConfig |
38 changes: 38 additions & 0 deletions
38
test/e2e/app-dir/revalidatetag-rsc/revalidatetag-rsc.test.ts
This file contains hidden or 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,38 @@ | ||
import { nextTestSetup } from 'e2e-utils' | ||
import { retry } from 'next-test-utils' | ||
|
||
describe('revalidateTag-rsc', () => { | ||
const { next } = nextTestSetup({ | ||
files: __dirname, | ||
}) | ||
|
||
it('should revalidate fetch cache if revalidateTag invoked via server action', async () => { | ||
const browser = await next.browser('/') | ||
const randomNumber = await browser.elementById('data').text() | ||
await browser.refresh() | ||
const randomNumber2 = await browser.elementById('data').text() | ||
expect(randomNumber).toEqual(randomNumber2) | ||
|
||
await browser.elementByCss('#submit-form').click() | ||
|
||
await retry(async () => { | ||
const randomNumber3 = await browser.elementById('data').text() | ||
expect(randomNumber3).not.toEqual(randomNumber) | ||
}) | ||
}) | ||
|
||
it('should revalidate fetch cache if revalidateTag invoked via server component', async () => { | ||
const browser = await next.browser('/') | ||
const randomNumber = await browser.elementById('data').text() | ||
await browser.refresh() | ||
const randomNumber2 = await browser.elementById('data').text() | ||
expect(randomNumber).toEqual(randomNumber2) | ||
|
||
await browser.elementByCss('#revalidate-via-page').click() | ||
await browser.waitForElementByCss('#home') | ||
await browser.elementByCss('#home').click() | ||
await browser.waitForElementByCss('#data') | ||
const randomNumber3 = await browser.elementById('data').text() | ||
expect(randomNumber3).not.toEqual(randomNumber) | ||
}) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.