Skip to content

chore: replace the deprecated json helper with Response.json - #16804

Open
Nic-Polumeyv wants to merge 11 commits into
version-3from
response-json-migration
Open

chore: replace the deprecated json helper with Response.json#16804
Nic-Polumeyv wants to merge 11 commits into
version-3from
response-json-migration

Conversation

@Nic-Polumeyv

Copy link
Copy Markdown
Contributor

With #16794, setResponse derives content-length from fixed bodies, so runtime responses no longer need the json helper to be served correctly on Node. This switches the runtime's json call sites to the native Response.json (deprecated by #15448). text call sites stay: new Response with a string body adds a default text/plain content-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 through text.

Stacked on #16794; retarget to version-3 once it merges.

@pkg-svelte-dev

pkg-svelte-dev Bot commented Aug 14, 2026

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from cf3e618:

pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/cf3e618b511a96a496eb06a0e69523a078551d44

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/kit/pr/16804

@svelte-docs-bot

Copy link
Copy Markdown

@changeset-bot

changeset-bot Bot commented Aug 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cf3e618

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

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

@Nic-Polumeyv Nic-Polumeyv changed the title chore: use Response.json in runtime responses chore: replace the deprecated json helper with Response.json 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.
Base automatically changed from response-json-runtime to version-3 August 14, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants