Unverified Commit 0ecde6bd authored by Shu Ding's avatar Shu Ding Committed by GitHub

Add test for client router state invalidation caused by cookie mutations (#53494)

Closes #53261. Closes NEXT-1478.
parent 3c84b3ac
......@@ -533,7 +533,6 @@ createNextDescribe(
expect(newJustPutIt).toEqual(newJustPutIt2)
})
// TODO: investigate flakey behavior with revalidate
it('should revalidate when cookies.set is called', async () => {
const browser = await next.browser('/revalidate')
const randomNumber = await browser.elementByCss('#random-cookie').text()
......@@ -549,6 +548,36 @@ createNextDescribe(
}, 'success')
})
it('should invalidate client cache on other routes when cookies.set is called', async () => {
const browser = await next.browser('/mutate-cookie')
await browser.elementByCss('#update-cookie').click()
let cookie
await check(async () => {
cookie = await browser.elementByCss('#value').text()
return parseInt(cookie) > 0 ? 'success' : 'failure'
}, 'success')
// Make sure the route is cached
await browser.elementByCss('#page-2').click()
await browser.elementByCss('#back').click()
// Modify the cookie
await browser.elementByCss('#update-cookie').click()
let newCookie
await check(async () => {
newCookie = await browser.elementByCss('#value').text()
return newCookie !== cookie && parseInt(newCookie) > 0
? 'success'
: 'failure'
}, 'success')
// Navigate to another page and make sure the cookie is not cached
await browser.elementByCss('#page-2').click()
const otherPageCookie = await browser.elementByCss('#value').text()
expect(otherPageCookie).toEqual(newCookie)
})
// TODO: investigate flakey behavior with revalidate
it('should revalidate when cookies.set is called in a client action', async () => {
const browser = await next.browser('/revalidate')
......
import { cookies } from 'next/headers'
import Link from 'next/link'
export default function Page() {
return (
<>
<Link id="back" href="/mutate-cookie">
back
</Link>
<p id="value">{cookies().get('test-cookie2')?.value}</p>
</>
)
}
import { cookies } from 'next/headers'
import Link from 'next/link'
async function updateCookie() {
'use server'
cookies().set('test-cookie2', Date.now())
}
export default function Page() {
return (
<>
<Link id="page-2" href="/mutate-cookie/page-2">
to page2
</Link>
<p id="value">{cookies().get('test-cookie2')?.value}</p>
<form action={updateCookie}>
<button id="update-cookie" type="submit">
Update Cookie
</button>
</form>
</>
)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment