Repository navigation
fix(cache): skip caching responses that set Astro.cookies or Astro.session - #17777
Viktor-Kolyshkin wants to merge 1 commit into
Conversation
…ssion The in-memory cache decided whether to store a response by checking only for a raw Set-Cookie header. Astro.cookies.set() and Astro.session write into an AstroCookies instance attached to the response, and that only gets flushed into a real Set-Cookie header by prepareResponse(), which runs after the cache has already stored the response. So a personalized response was cached and replayed to other users without their own Set-Cookie. hasSetCookieHeader() now also returns true when the response has pending writes on its attached AstroCookies, read through the non-destructive headers() peek so the later flush in prepareResponse() is unaffected.
🦋 Changeset detectedLatest commit: 31f4ca8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 422 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Merging this PR will degrade performance by 15.17%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Simulation | Build: hybrid site (static + server) |
1.4 s | 1.7 s | -15.74% |
| ❌ | Simulation | Build: full server site |
1.4 s | 1.6 s | -14.6% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing Viktor-Kolyshkin:fix/memory-cache-session-cookies (31f4ca8) with main (dac1768)
|
Superseded by #17781. |
Changes
Closes #17775.
The in-memory response cache stored responses that write a cookie through
Astro.cookiesorAstro.session, then replayed that personalized response to other visitors without their ownSet-Cookie.The cache only checked for a raw
Set-Cookieheader before storing.Astro.cookies.set()/Astro.sessionwrites land on anAstroCookiesinstance attached to the response by Symbol, and that's only flushed into a realSet-Cookieheader byprepareResponse(), which runs after the cache has already stored the response. So the header check saw nothing at store time.hasSetCookieHeader()now also treats a response as carrying a cookie when its attachedAstroCookieshas pending writes, checked with the non-destructiveheaders()peek so the later flush inprepareResponse()still happens normally. A response with an attached but emptyAstroCookies(nothing ever set) still caches as before.Testing
Added two unit tests in
memory-provider.test.ts: one confirms a response with a pendingAstro.cookieswrite is not cached and a second request re-renders instead of getting the first user's response, the other confirms a response with an emptyAstroCookiesstill caches. Both the initial store path and the stale-while-revalidate path go through the same check.Docs
None needed. This is a bug fix with no public API changes.