Open serhalp opened 1 month ago
I had a look at the repro and it seems the x-middleware-set-cookie
header is getting set correctly, so I'd imagine the problem is in the part that reads that header and combines the contents with the actual cookies in the request, i.e. here: https://github.com/vercel/next.js/pull/65008/files#diff-d16b8f6eab3df537748d15ebbf5901a5b4700dff01fbf030c29c7a18d89c5ef6R108
Not sure why this is only a problem with the Next Runtime, perhaps something to do with its use of AsyncLocalStorage?
next@v15.0.0-canary.160 unskipped some tests in this commit These tests hadn't been running for some time.
Many of these tests fail on Netlify. For example:
If you run the fixture locally, it appears to work as expected with
next dev
,ntl dev
, andntl serve
, but it does not work as expected when deployed to Netlify (more detail below).These tests and fix for the issue being tested were originally introduced in next.js in https://github.com/vercel/next.js/pull/65008. My guess is they wouldn't have passed at the time on Netlify. Deploying the fixture exhibits the same behaviour with older canary versions and with next@latest.
I believe this is possibly a confusing intersection of three unrelated things:
This is largely conjecture, but what I observe is that when reloading the fixture page repeatedly I sometimes see both cookies set on the page and on the response, sometimes one is missing on the page but not headers, and sometimes they are missing on both. It's nondeterministic and confusing. However, if I remove the
<Link href="/rsc-cookies-delete">
(or addprefetch={false}
), the behaviour is much simpler: the two cookies are always set on the response but the values on the page always reflect the previous values; e.g.which is what led me to the above conclusions. This is the same on next@latest and next@canary.
I have no idea why this cannot be reproduced locally. It might be timing related?
You can verify the above with this repo (which is mostly just a copy of the test fixture): https://github.com/serhalp/nextjs-canary-rsc-cookies-repro.
This has never been reported by users AFAIK.
Data
The following is parsed automatically by the Next.js repo e2e test report generator.
test: test/e2e/app-dir/app-middleware/app-middleware.test.ts reason: Cookies modified then read back again in an RSC return unmodified values