fix(cache): preserve binary fetch response bodies - #2907
Conversation
|
/bigbonk review for issues |
commit: |
|
Performance benchmarksCompared 0 improved · 0 regressed · 6 within ±1.5%
View detailed results and traces 🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head |
|
@james-elicx Bonk workflow was cancelled. View workflow run · To retry, trigger Bonk again. |
|
/bigbonk review for issues |
/bigbonk reviewVerdict: LGTM. This is a faithful, correct port of Next.js's What I verified1. Matches Next.js exactly. I checked the upstream
2. Version bump is correct and effective. 3. No cross-contamination with
So the base64 change is correctly isolated to the 4. Runtime availability confirmed. 5. Edge cases fine.
Test results
Minor (non-blocking) suggestions
Nice, tight fix. |
|
Review posted to PR #2907. SummaryVerdict: LGTM — no blocking issues. PR #2907 correctly fixes binary/compressed fetch response bodies being corrupted on cache replay (previously serialized through
I flagged two minor, non-blocking notes (a cosmetic inconsistency in which Response reference status/url read from, and a clarification about gzip decoding parity). Neither requires changes. |
Summary
fetch()response bodies as base64 instead of lossy UTF-8 textContext
Response.text()replaces invalid UTF-8 sequences. The fetch cache previously serialized every response throughtext()while retaining the original headers, so binary or compressed bodies could be irreversibly changed on a cache hit.This follows Next.js's
CachedFetchDatarepresentation inpatch-fetch.ts, which stores response bytes as base64.The bug was reproduced on Cloudflare Workers with a tagged fetch whose response contained compressed bytes. The first fetch returned the original bytes, while the cached replay contained UTF-8 replacement bytes.
Validation
vp test run tests/fetch-cache.test.ts(146 passed)vp test run tests/isr-cache.test.ts tests/kv-cache-handler.test.ts(136 passed)vp test run tests/shims.test.ts(1,291 passed)vp check packages/vinext/src/shims/fetch-cache.ts tests/fetch-cache.test.tsvp run vinext#buildgit diff --check