mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
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):  Co-authored-by: JJ Kasper <[email protected]>
22 lines
510 B
JavaScript
22 lines
510 B
JavaScript
import { cookies } from 'next/headers'
|
|
import Link from 'next/link'
|
|
import { Form } from '../form'
|
|
|
|
export default async function Page() {
|
|
return (
|
|
<div>
|
|
<p id="total-cookies">Total Cookie Length: {(await cookies()).size}</p>
|
|
<Link href="/rsc-cookies-delete" prefetch={false}>
|
|
To Delete Cookies Route
|
|
</Link>
|
|
|
|
<Form
|
|
action={async () => {
|
|
'use server'
|
|
return (await cookies()).get('rsc-secure-cookie').value
|
|
}}
|
|
/>
|
|
</div>
|
|
)
|
|
}
|