Unverified Commit d4e390d0 authored by Philippe Serhal's avatar Philippe Serhal Committed by GitHub

test: de-flake rsc-cookies e2e tests (#71319)

Since the `/rsc-cookies-delete` path has a side effect (it runs a
middleware code path that deletes client cookies), prefetching this link
leads to unpredictable behaviours and possible failures in tests that
use this fixture, [such as this
one](https://github.com/vercel/next.js/blob/047baaba7d53326f157adc3aaf4b3fb3e13813c2/test/e2e/app-dir/app-middleware/app-middleware.test.ts#L126).

I fixed this with `prefetch={false}` but [per the
docs](https://nextjs.org/docs/pages/api-reference/components/link#prefetch)
it might be preferable to just use a plain `<a>` tag? I'm happy to make
that change if you prefer. Alternatively, maybe a `GET` shouldn't have
side effects; we could use a form here, fetch, or Server Action or
something instead.

Here's an example race when running the fixture manually (cookie 1 has
been unset by the `/rsc-cookies-delete` prefetch):

![Screenshot 2024-10-15 at 14 13
13](https://github.com/user-attachments/assets/b8e21a74-f8fd-4e7c-ab2a-a4ce17212806)
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent e40ea769
...@@ -6,7 +6,9 @@ export default async function Page() { ...@@ -6,7 +6,9 @@ export default async function Page() {
return ( return (
<div> <div>
<p id="total-cookies">Total Cookie Length: {(await cookies()).size}</p> <p id="total-cookies">Total Cookie Length: {(await cookies()).size}</p>
<Link href="/rsc-cookies-delete">To Delete Cookies Route</Link> <Link href="/rsc-cookies-delete" prefetch={false}>
To Delete Cookies Route
</Link>
<Form <Form
action={async () => { action={async () => {
......
...@@ -11,7 +11,9 @@ export default async function Page() { ...@@ -11,7 +11,9 @@ export default async function Page() {
<p id="rsc-cookie-1">Cookie 1: {rscCookie1}</p> <p id="rsc-cookie-1">Cookie 1: {rscCookie1}</p>
<p id="rsc-cookie-2">Cookie 2: {rscCookie2}</p> <p id="rsc-cookie-2">Cookie 2: {rscCookie2}</p>
<p id="total-cookies">Total Cookie Length: {(await cookies()).size}</p> <p id="total-cookies">Total Cookie Length: {(await cookies()).size}</p>
<Link href="/rsc-cookies-delete">To Delete Cookies Route</Link> <Link href="/rsc-cookies-delete" prefetch={false}>
To Delete Cookies Route
</Link>
<Form <Form
action={async () => { action={async () => {
'use server' 'use server'
......
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