mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 00:09:23 +02:00
[PR #887] fix(shims): skip body copy for GET/HEAD in NextRequest constructor #919
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#919
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/887
Author: @agm151515
Created: 4/24/2026
Status: 🔄 Open
Base:
main← Head:fix/nextrequest-skip-body-for-get-head📝 Commits (1)
dc04a22fix(shims): skip body copy for GET/HEAD in NextRequest constructor📊 Changes
2 files changed (+48 additions, -3 deletions)
View changed files
📝
packages/vinext/src/shims/server.ts(+7 -3)📝
tests/shims.test.ts(+41 -0)📄 Description
Summary
When
NextRequestis constructed from an existingRequest, itsconstructor forwards
body: req.bodytosuper()unconditionally.The Fetch spec (and workerd) throw
TypeError: Request with a GET or HEAD method cannot have a body.whenever
init.bodyis non-null and the method isGET/HEAD.In Cloudflare Workers, incoming
GET/HEADrequests exposerequest.bodyas a non-nullReadableStreamwhenever the requestcarries
Content-LengthorTransfer-Encodingframing. That happensin the wild — e.g. some email image-proxy fetchers of tracking pixels
send
GETwith aContent-Lengthheader — so the proxy/middlewareblock in the generated RSC entry throws on every affected request,
logs
[vinext] Middleware error: TypeError: …, and returns 500.Reproduced via
wrangler dev --localagainst a minimal worker:Fix gates
body/duplexbehind a method check. Behavior forPOST/PUT/PATCH/DELETEetc. is unchanged.Test plan
tests/shims.test.tsreproduces the bugin Node (by overriding
bodyon a normal Request viaObject.defineProperty) — fails before the fix, passes after.NextRequesttests still pass (pnpm test:unit -t NextRequest→ 21 passed).pnpm test:unit→ 2971/2971).pnpm fmt:checkandpnpm lintclean on modified files.Downstream context for maintainers: this was observed in production on
scoregap.com with vinext 0.0.43. Filed locally as GitHub issue #35 in
our app repo. Happy to adjust style/commit-msg to match project
conventions.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.