chore: replace the deprecated json helper with Response.json - #16804
Open
Nic-Polumeyv wants to merge 11 commits into
Open
chore: replace the deprecated json helper with Response.json#16804Nic-Polumeyv wants to merge 11 commits into
json helper with Response.json#16804Nic-Polumeyv wants to merge 11 commits into
Conversation
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/cf3e618b511a96a496eb06a0e69523a078551d44Open in |
🦋 Changeset detectedLatest commit: cf3e618 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Response.json in runtime responsesjson helper with Response.json
Rich-Harris
approved these changes
Aug 14, 2026
Rich-Harris
pushed a commit
that referenced
this pull request
Aug 14, 2026
#16794) On Node, `setResponse` streams every `response.body` through a reader loop, so a response without a pre-computed `content-length` header is served with chunked transfer encoding. That is why the runtime can't move off the deprecated `json`/`text` helpers, whose only load-bearing job is stamping that header, and why a plain `Response.json` returned from an endpoint is served chunked today. Every other runtime derives the header from fixed bodies at serve time. `setResponse` now races the body's first reads against a `setImmediate` deadline before writing the head. A fixed body settles value-then-done on microtasks, so it is sent with a measured `content-length`; a body that leaves a read pending is a genuine stream and goes through the existing streaming path unchanged, with its headers delayed by at most one tick. Nothing is added when the response already carries a `content-length` or a `transfer-encoding` (proxied responses can carry the latter, and the pair would be invalid). Same approach as hono's node-server. `json`/`text` are untouched. Retiring them internally becomes a follow-up; its one catch is the `http.response.body.size` span attribute, which reads the `content-length` header. #16804 is stacked on this.
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.
With #16794,
setResponsederivescontent-lengthfrom fixed bodies, so runtime responses no longer need thejsonhelper to be served correctly on Node. This switches the runtime'sjsoncall sites to the nativeResponse.json(deprecated by #15448).textcall sites stay:new Responsewith a string body adds a defaulttext/plaincontent-type where the helper adds none, so replacing those changes response headers and is a separate decision. Tracing is unaffected, since page and error documents still go throughtext.Stacked on #16794; retarget to
version-3once it merges.