encode streamed chunks - #9136
Merged
Merged
Conversation
dummdidumm
approved these changes
Feb 20, 2023
Merged
5 tasks
Rich-Harris
added a commit
that referenced
this pull request
Aug 20, 2026
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: - [x] 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 - [x] This message body should clearly illustrate what problems it solves. - [ ] Ideally, include a test that fails without this PR but passes with it. ### Tests - [x] Run the tests with `pnpm test` and lint the project with `pnpm lint` and `pnpm check` ### Changesets - [x] 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:`. --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>
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.
It turns out that if
response.bodyis aReadableStream, it must be aReadableStream<Uint8Array>. This escaped notice before, because Node does its own thing, quelle surprisePlease don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.