Repository navigation
fix(handler): don't stream a background refresh to a stale request - #116
RihanArfan wants to merge 1 commit into
Conversation
|
@RihanArfan is attempting to deploy a commit to the unjs Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
| let resolveStatuses: WeakMap<HTTPEvent, CacheStatus> | undefined; | ||
|
|
||
| /** The status of the foreground resolution this event leads, if it leads one. */ | ||
| export function resolveStatus(event: HTTPEvent): CacheStatus | undefined { |
With
stream: true, a cached handler decides whether to stream the body to the request, and whichx-cachevalue to send, from a status stored per request event. Every cached call made with the same event writes to it and nothing clears it, so another cached call on the same request can change both decisions.This shows up in two ways:
swr, if middleware calls a cached function with the event first, a request for an expired entry waits for the full render and gets the new body withx-cache: MISS. It should get the stored copy right away withx-cache: STALE.x-cacheto its own status.Each resolution now passes its own status to
serializeasctx.status, and the per-event status is removed. Handlers withoutstream: truearen't affected. Regression tests for both cases are included.@pi0x found this while reviewing #109 and #110 (1, 2, 3). It also happens on
mainwithout those PRs, so it's split out here. #109 and #110 are stacked on this PR, for nitrojs/nitro#4904.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Documentation
resolveStatusAPI reference; the helper is no longer available.