Repository navigation
Conversation
bufferRequest handed every arrayBuffer() caller the same cached ArrayBuffer, and bytes() a view over it, so a middleware that wrote into its read changed the body every later layer saw, and one that transferred it left the handler reading an empty body. Each read now goes through a fresh Response over the cached bytes, whose constructor copies them.
The buffered request built its blob from the raw bytes, so blob().type was always empty where a native Request takes it from the Content-Type, and forwarding `await req.blob()` dropped it. blob() now reads through the same Response as the other forms, which applies the request's headers.
When a downstream layer threw and the middleware's catch recovered with `yield new Response(...)`, the runtime returned that response without closing the generator, so its finally block never ran. It now calls gen.return() when gen.throw() leaves the generator suspended, as the other paths that receive a yielded Response already do.
…equest bufferRequest returns a proxy, which only helps when the caller can hand it on. TanStack Start, SvelteKit and React Router give the route the same Request their middleware saw. bufferRequestInPlace redefines the body readers on the request itself, sharing the readers bufferRequest uses. Closes supabase#63 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
bufferRequestInPlace(req). It redefinesarrayBuffer,bytes,blob,text,json,formDataandcloneas non-enumerable own properties of the request and returns the same request. It is a no-op without a body, after the body was used, and when called twice.bufferRequestandbufferRequestInPlaceshare one privatebufferedReadersfactory, so the in-place variant gets the same per-read copies and content-type handling.clone()on an in-place request returns abufferRequestproxy over the same cache.bufferRequest's TSDoc now says when to use which.Why
bufferRequestreturns a proxy, which works when the caller can hand the proxy on (Hono'sc.req.raw, H3'sevent.req). TanStack Start, SvelteKit (event.request) and React Router (requestin loaders and actions) hand the route the sameRequestobject their middleware saw. In a bridge for those, an entry that reads the body consumes the stream and the route's ownrequest.json()throws. Every bridge currently carries its own copy of this code, which has to trackbufferRequest's behavior.Closes #63
Testing
src/core/runtime.test.ts: every read form on the same object, a stack and then the route reading the same request, form bodies, per-read copies,clone(), and the no-op cases.test/runtimes/workers: the built dist buffers a workerdRequestin place, runs a stack that reads the body, and reads it again from the same object.Ran locally:
pnpm format:check,pnpm lint,pnpm typecheck,pnpm typecheck:min,pnpm build,pnpm typecheck:consumer,pnpm smoke,pnpm check-exports,pnpm test(135 tests),pnpm test:workers,pnpm test:bunand the JSR dry run. I did not runpnpm test:deno(no Deno locally).Alternatives
bufferRequest({ inPlace: true }) instead of a second export. A separate name made the different return contract (same object versus a proxy) clearer.voidlike the existing bridge copies. Returning the request lets it be used inline.Prior art: better-supabase bridges/shared.ts (
bufferInPlace).🤖 Generated with Claude Code