Skip to content

Use async_sequence in ReadableStream.from - #1372

Merged
MattiasBuelens merged 15 commits into
whatwg:mainfrom
MattiasBuelens:rs-from-async-sequence
Jul 17, 2026
Merged

Use async_sequence in ReadableStream.from#1372
MattiasBuelens merged 15 commits into
whatwg:mainfrom
MattiasBuelens:rs-from-async-sequence

Conversation

@MattiasBuelens

@MattiasBuelens MattiasBuelens commented May 1, 2026

Copy link
Copy Markdown
Collaborator

Replace our manual async iterator logic with the new Web IDL async_sequence<T> type and its associated operations (added in whatwg/webidl#1397).

This comes with one behavioral change: ReadableStream.from("abc") used to iterate over the Unicode code points of the string (per String.prototype[Symbol.iterator]), but this will now throw a TypeError instead. This is covered by the new WPTs.

Developers who want to create a ReadableStream from a string should update their code to either:

  • ReadableStream.from(["abc"]) for a stream with a single chunk "abc"
  • ReadableStream.from([..."abc"]) for a stream with three chunks "a", "b", "c"

Supersedes #1310. (Thanks to @lucacasonato for getting this started!)

(See WHATWG Working Mode: Changes for more details.)


Preview | Diff

@MattiasBuelens

Copy link
Copy Markdown
Collaborator Author

The spec text doesn't build yet, because I'm waiting for a new release of Bikeshed that includes speced/bikeshed#3297.

You can already build it locally by manually updating the widlparser dependency:

pipx install bikeshed
pipx inject bikeshed --force widlparser==1.5.0
make local

@MattiasBuelens
MattiasBuelens requested review from alrra, annevk and saschanaz and removed request for alrra May 1, 2026 13:56
@MattiasBuelens
MattiasBuelens force-pushed the rs-from-async-sequence branch from d78c683 to c7762c2 Compare May 1, 2026 14:23
Comment thread index.bs
their constructor steps.

<div algorithm="create a ReadableStream from an async sequence">
To <dfn export lt="create from async sequence|create from an async sequence" for="ReadableStream">create</dfn>

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lucacasonato Would this work for whatwg/fetch#1291?

@MattiasBuelens
MattiasBuelens force-pushed the rs-from-async-sequence branch from c7762c2 to 68ae88a Compare May 1, 2026 14:30

@annevk annevk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modulo green CI. WebKit supports this change. cc @youennf

@MattiasBuelens
MattiasBuelens force-pushed the rs-from-async-sequence branch 3 times, most recently from 8bb3507 to 68ae88a Compare May 5, 2026 05:48
@MattiasBuelens
MattiasBuelens force-pushed the rs-from-async-sequence branch from 68ae88a to 7511a41 Compare May 5, 2026 17:38
@MattiasBuelens
MattiasBuelens force-pushed the rs-from-async-sequence branch from 68ae88a to 5ca9d87 Compare May 5, 2026 17:42
@MattiasBuelens

Copy link
Copy Markdown
Collaborator Author

CI is (finally) green. Turns out Bikeshed needed to be updated across quite a few tools and services. 😅

Does Chromium and/or Gecko support this change? @ricea perhaps?

@lucacasonato lucacasonato left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@annevk annevk added the agenda+ To be discussed at a triage meeting label Jun 20, 2026
@noamr

noamr commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

@ricea for chromium
This seems like a good change to me, WDYT?

@saschanaz saschanaz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gecko supports this.

@ricea

ricea commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Chromium supports this.

I haven't had time to check in detail whether this has any unexpected semantic side effects, but the approach looks fine.

@MattiasBuelens

Copy link
Copy Markdown
Collaborator Author

Thanks for the responses. I'll start opening implementation bugs.

I haven't had time to check in detail whether this has any unexpected semantic side effects, but the approach looks fine.

The async_sequence<T> machinery in Web IDL was largely based on the original semantics for ReadableStream.from(), so the behavior should be unchanged. Well, except for strings, but that's explained above and tested in web-platform-tests/wpt#59594. (By the way, reviews welcome! 😉)

lando-worker Bot pushed a commit to mozilla-firefox/firefox that referenced this pull request Jul 14, 2026
… a=testonly

Automatic update from web-platform-tests
Streams: reject strings in `ReadableStream.from` (#59594)

Follows whatwg/streams#1372.
--

wpt-commits: 78df415978b3a770efa7da946cc212902c07cb38
wpt-pr: 59594
@MattiasBuelens MattiasBuelens changed the title Use async_sequence in ReadableStream.from Use async_sequence<T> in ReadableStream.from Jul 17, 2026
@MattiasBuelens MattiasBuelens changed the title Use async_sequence<T> in ReadableStream.from Use async_sequence in ReadableStream.from Jul 17, 2026
@MattiasBuelens
MattiasBuelens merged commit 2999707 into whatwg:main Jul 17, 2026
3 checks passed
@MattiasBuelens
MattiasBuelens deleted the rs-from-async-sequence branch July 17, 2026 06:46
petamoriken added a commit to petamoriken/deno that referenced this pull request Jul 19, 2026
Replace the ad-hoc async iterable converter with Web IDL async_sequence
conversion (GetMethod, Object-only, CreateAsyncFromSyncIterator) and wire
ReadableStream.from to async_sequence<any>, per whatwg/streams#1372.

Closes denoland#35777
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

7 participants