-
Notifications
You must be signed in to change notification settings - Fork 27k
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
Stale request.cookies
value if updated in middleware without explicitly passing new headers to NextResponse
#57655
Comments
tried |
|
I am also having the same issue. I think updating cookies inside middleware should update the server component's cookies() function while in the same request. It's because middleware runs in the edge runtime only maybe? |
I have the same issue adding
|
Any solution here ? I am facing the same issue regarding cookies when I want to do redirect in the middleware. |
Duplicate of #49442 |
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Link to the code that reproduces this issue
https://github.com/boreyko1/next-stale-cookie-middleware-repro
To Reproduce
next dev
Current vs. Expected behavior
Setting or updating a cookie value in the middleware does not make it updated further down in the request i.e. using in page server components.
Logs from the repro describing the issue:
You can see above that
[page server component]
is not updated with the new value from the middleware even thoughrequest.cookies.get('test').value
returns an updated one. Basically it lags oneSet-Cookie
response behind in that case.I managed to get the expected behavior by manually passing
{ headers: new Headers(request.headers) }
onNextResponse.next()
init. But this is not that obvious one needs to explicitly referencerequest.headers
in theresponse.headers
in order for it to work properly in the current ongoing request.Logs after the workaround and expected behavior:
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 23.0.0: Fri Sep 15 14:41:43 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T6000 Binaries: Node: 20.8.1 npm: 9.6.4 Yarn: 3.3.1 pnpm: 7.9.0 Relevant Packages: next: 14.0.1-canary.1 eslint-config-next: N/A react: 18.2.0 react-dom: 18.2.0 typescript: 5.1.3 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
App Router, Middleware / Edge (API routes, runtime)
Additional context
I reproduced this issue with next 13, next 14 and
14.0.1-canary.1
. Even though a possible userland workaround is described above I still do not think it is an expected behavior. Docs also do not mention anything like that in the Using Cookies section for the middleware.Let me know if I can help somehow or it is not an issue at all. If so, I can probably make a docs PR then.
Thanks!
The text was updated successfully, but these errors were encountered: