Skip to content

chore: build streamed responses from async generators - #16847

Merged
Rich-Harris merged 3 commits into
version-3from
stream-from-generators
Aug 20, 2026
Merged

chore: build streamed responses from async generators#16847
Rich-Harris merged 3 commits into
version-3from
stream-from-generators

Conversation

@Nic-Polumeyv

Copy link
Copy Markdown
Contributor

Four places hand-write the producer side of a stream. server/page/render.js and server/data/index.js each construct a ReadableStream whose start enqueues an encoded head, loops an async iterable of chunks and closes; form-utils.js LazyFile.stream() drives read_range through a pull adapter that re-tracks a cursor the generator already knows; and utils/streaming.js create_async_iterator implements [Symbol.asyncIterator]/next by hand with two index cursors.

This replaces them with async generators and ReadableStream.from, which server/index.js already relies on for promised read results. The two response pumps share a stream_text(head, chunks) helper, LazyFile.stream() becomes a for await over read_range, and iterate becomes an async function* over the deferred list.

Two deliberate deltas: the response streams lose type: 'bytes' (added alongside the encoding fix in #9136; Response only requires Uint8Array chunks, which .from over encoded strings provides), and an incomplete LazyFile now errors with an Error instead of a bare string.


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

@pkg-svelte-dev

pkg-svelte-dev Bot commented Aug 19, 2026

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from 5ebbd02:

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

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

@changeset-bot

changeset-bot Bot commented Aug 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5ebbd02

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

Comment thread packages/kit/src/runtime/utils.js Outdated
@svelte-docs-bot

Copy link
Copy Markdown

@Nic-Polumeyv
Nic-Polumeyv marked this pull request as draft August 19, 2026 18:00
@Nic-Polumeyv

Copy link
Copy Markdown
Contributor Author

Pushed a fallback for runtimes without ReadableStream.from. It's still unreleased in Bun (oven-sh/bun#33193 landed on main, latest release is 1.3.14), so streamed responses would throw there. Also routes the #16622 site through it, and fixes the lint failure.

@Nic-Polumeyv
Nic-Polumeyv marked this pull request as ready for review August 20, 2026 03:32
@Rich-Harris
Rich-Harris merged commit 9b3d195 into version-3 Aug 20, 2026
26 of 27 checks passed
@Rich-Harris
Rich-Harris deleted the stream-from-generators branch August 20, 2026 12:51
Rich-Harris pushed a commit that referenced this pull request Aug 21, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to version-3, this PR
will be updated.

⚠️⚠️⚠️⚠️⚠️⚠️

`version-3` is currently in **pre mode** so this branch has prereleases
rather than normal releases. If you want to exit prereleases, run
`changeset pre exit` on `version-3`.

⚠️⚠️⚠️⚠️⚠️⚠️

# Releases
## @sveltejs/adapter-bun@1.0.0-next.1

### Minor Changes

- feat: add a Bun-native adapter with static file serving and
single-executable support
([#16695](#16695))

### Patch Changes

- Updated dependencies
[[`9b3d195`](9b3d195),
[`385d378`](385d378),
[`3782448`](3782448),
[`d0d3a33`](d0d3a33),
[`4b7a483`](4b7a483),
[`e325d7d`](e325d7d),
[`4f63c79`](4f63c79)]:
  - @sveltejs/kit@3.0.0-next.25
## @sveltejs/kit@3.0.0-next.25

### Minor Changes

- feat: add an `applyReroute` helper for adapters that support split
serverless function deployments
([#16665](#16665))

### Patch Changes

- chore: build streamed responses from async generators
([#16847](#16847))

- fix: tweak response logging for remote requests
([#16865](#16865))

- fix: discard invalidation results when a navigation completes while
they load ([#16852](#16852))

- fix: route dev-server response logging through Vite's logger so it
respects `logLevel` and `customLogger`
([#16858](#16858))

- chore: read build-time config from defines on the server instead of
carrying it in `options`
([#16873](#16873))

- chore: read `options` from a single module instead of passing it
through the server runtime
([#16871](#16871))
## @sveltejs/adapter-netlify@7.0.0-next.10

### Patch Changes

- fix: correctly apply `reroute` results for apps configured with split
serverless functions
([#16665](#16665))
- Updated dependencies
[[`9b3d195`](9b3d195),
[`385d378`](385d378),
[`3782448`](3782448),
[`d0d3a33`](d0d3a33),
[`4b7a483`](4b7a483),
[`e325d7d`](e325d7d),
[`4f63c79`](4f63c79)]:
  - @sveltejs/kit@3.0.0-next.25
## @sveltejs/adapter-vercel@7.0.0-next.8

### Patch Changes

- fix: omit ISR data endpoints for server-only routes
([#16731](#16731))

- fix: correctly apply `reroute` results for apps configured with split
serverless functions
([#16665](#16665))
- Updated dependencies
[[`9b3d195`](9b3d195),
[`385d378`](385d378),
[`3782448`](3782448),
[`d0d3a33`](d0d3a33),
[`4b7a483`](4b7a483),
[`e325d7d`](e325d7d),
[`4f63c79`](4f63c79)]:
  - @sveltejs/kit@3.0.0-next.25

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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