forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
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
125 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
test/e2e/app-dir/revalidatetag-rsc/app/RevalidateViaForm.tsx
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,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 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 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 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,23 @@ | ||
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'], | ||
}, | ||
} | ||
).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 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: { tag: string } | ||
}) => { | ||
const { tag } = 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 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 |
35 changes: 35 additions & 0 deletions
35
test/e2e/app-dir/revalidatetag-rsc/revalidatetag-rsc.test.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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { nextTestSetup } from 'e2e-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 browser.waitForIdleNetwork() | ||
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) | ||
}) | ||
}) |