Skip to content

Commit 848cdb2

Browse files
Merge pull request #161 from MattiasBuelens/update-20250403
Update to spec version of 3 April 2025
2 parents 5138551 + ef98260 commit 848cdb2

38 files changed

+2430
-9877
lines changed

.github/workflows/pull-request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
with:
2828
node-version: ${{ matrix.node-version }}
2929
cache: npm
30-
- run: npm ci
30+
- run: npm ci --workspaces
3131
env:
3232
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
3333
- run: npm run test:types

.github/workflows/push.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
with:
2121
node-version: ${{ matrix.node-version }}
2222
cache: npm
23-
- run: npm ci
23+
- run: npm ci --workspaces
2424
env:
2525
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
2626
- run: npm run test:types
@@ -32,7 +32,7 @@ jobs:
3232
name: ${{ matrix.browser }}
3333
runs-on: ubuntu-latest
3434
container:
35-
image: mcr.microsoft.com/playwright:v1.49.1-noble
35+
image: mcr.microsoft.com/playwright:v1.54.2-noble
3636
strategy:
3737
fail-fast: false
3838
matrix:

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
> - 🏠 Internal
1111
> - 💅 Polish
1212
13+
## Unreleased
14+
15+
* 👓 Align with [spec version `080852c`](https://github.com/whatwg/streams/tree/080852ccd709e063cc6af239ae07fc040e365179/) ([#161](https://github.com/MattiasBuelens/web-streams-polyfill/pull/161))
16+
1317
## 4.1.0 (2025-01-05)
1418

1519
* 👓 Align with [spec version `fa4891a`](https://github.com/whatwg/streams/tree/fa4891a35ff05281ff8ed66f8ad447644ea7cec3/) ([#156](https://github.com/MattiasBuelens/web-streams-polyfill/pull/156))

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2024 Mattias Buelens
3+
Copyright (c) 2025 Mattias Buelens
44
Copyright (c) 2016 Diwank Singh Tomer
55

66
Permission is hereby granted, free of charge, to any person obtaining a copy

README.md

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ This library comes in multiple variants:
2626
Recommended for use in web apps supporting older browsers through a `<script>` tag.
2727

2828
Each variant also includes TypeScript type definitions, compatible with the DOM type definitions for streams included in TypeScript.
29-
These type definitions require TypeScript version 4.7 or higher.
29+
These type definitions require TypeScript version 5.7 or higher.
3030

3131
In version 4, the list of variants was reworked to have more modern defaults and to reduce the download size of the package.
3232
See the [migration guide][migrating] for more information.
@@ -57,6 +57,45 @@ import "web-streams-polyfill/polyfill";
5757
const readable = new ReadableStream();
5858
```
5959

60+
> [!WARNING]
61+
> **Compatibility with built-in streams**
62+
>
63+
> If your browser or runtime already supports Web Streams, loading the polyfill will *unconditionally* replace
64+
> the global `ReadableStream`, `WritableStream` and `TransformStream` classes with the polyfill's versions.
65+
> However, browser APIs like `fetch()` will still return stream objects using the *built-in* stream classes.
66+
> This can lead to surprising results, for example `Response.body` will not be `instanceof ReadableStream`
67+
> after the polyfill replaces the global `ReadableStream` class.
68+
>
69+
> Consider using `ReadableStream.from()` to convert a built-in stream (e.g. from `fetch()`) to a polyfilled stream,
70+
> or try [loading the polyfill conditionally](#conditional-loading) if you don't always need the polyfill.
71+
>
72+
> See [issue #20](https://github.com/MattiasBuelens/web-streams-polyfill/issues/20) for more details.
73+
74+
## Conditional loading
75+
76+
Web Streams are [widely supported][mdn-browser-compatibility] across all modern browsers
77+
(including Chrome, Firefox and Safari) and server runtimes (including Node.js, Deno and Bun).
78+
Consider using feature detection to check if your platform's built-in streams implementation can fulfill your app's needs,
79+
and load the polyfill only when needed.
80+
81+
Here are a couple of examples to load the polyfill conditionally:
82+
```js
83+
// Check for basic ReadableStream support
84+
if (!globalThis.ReadableStream) {
85+
await import("web-streams-polyfill/polyfill");
86+
}
87+
88+
// Check for basic TransformStream support
89+
if (!globalThis.TransformStream) {
90+
await import("web-streams-polyfill/polyfill");
91+
}
92+
93+
// Check for async iteration support
94+
if (typeof globalThis.ReadableStream?.prototype[Symbol.asyncIterator] !== 'function') {
95+
await import("web-streams-polyfill/polyfill");
96+
}
97+
```
98+
6099
## Compatibility
61100
62101
The `polyfill` and `ponyfill` variants work in any ES2015-compatible environment.
@@ -80,7 +119,7 @@ When using TypeScript, make sure your [`moduleResolution`](https://www.typescrip
80119
81120
## Compliance
82121
83-
The polyfill implements [version `fa4891a` (3 Dec 2024)][spec-snapshot] of the streams specification.
122+
The polyfill implements [version `080852c` (3 Apr 2025)][spec-snapshot] of the streams specification.
84123
85124
The polyfill is tested against the same [web platform tests][wpt] that are used by browsers to test their native implementations.
86125
The polyfill aims to pass all tests, although it allows some exceptions for practical reasons:
@@ -104,6 +143,7 @@ Thanks to these people for their work on [the original polyfill][creatorrr-polyf
104143
105144
[spec]: https://streams.spec.whatwg.org
106145
[ref-impl]: https://github.com/whatwg/streams
146+
[mdn-browser-compatibility]: https://developer.mozilla.org/en-US/docs/Web/API/Streams_API#browser_compatibility
107147
[ponyfill]: https://github.com/sindresorhus/ponyfill
108148
[migrating]: https://github.com/MattiasBuelens/web-streams-polyfill/blob/master/MIGRATING.md
109149
[promise-support]: https://kangax.github.io/compat-table/es6/#test-Promise
@@ -112,8 +152,8 @@ Thanks to these people for their work on [the original polyfill][creatorrr-polyf
112152
[ws-controller-signal]: https://streams.spec.whatwg.org/#ws-default-controller-signal
113153
[abortcontroller-polyfill]: https://www.npmjs.com/package/abortcontroller-polyfill
114154
[mdn-byob-read]: https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamBYOBReader/read
115-
[spec-snapshot]: https://streams.spec.whatwg.org/commit-snapshots/fa4891a35ff05281ff8ed66f8ad447644ea7cec3/
116-
[wpt]: https://github.com/web-platform-tests/wpt/tree/7ef95a1c3f1c178e455b21569eddb31af7c3691f/streams
117-
[wpt-async-iterator-prototype]: https://github.com/web-platform-tests/wpt/blob/7ef95a1c3f1c178e455b21569eddb31af7c3691f/streams/readable-streams/async-iterator.any.js#L24
155+
[spec-snapshot]: https://streams.spec.whatwg.org/commit-snapshots/080852ccd709e063cc6af239ae07fc040e365179/
156+
[wpt]: https://github.com/web-platform-tests/wpt/tree/186a9fd7abc3d9c31e2b37680be757e992af9e3a/streams
157+
[wpt-async-iterator-prototype]: https://github.com/web-platform-tests/wpt/blob/186a9fd7abc3d9c31e2b37680be757e992af9e3a/streams/readable-streams/async-iterator.any.js#L24
118158
[stub-async-iterator-prototype]: https://github.com/MattiasBuelens/web-streams-polyfill/blob/v4.0.0/src/lib/readable-stream/async-iterator.ts#L143-L147
119159
[creatorrr-polyfill]: https://github.com/creatorrr/web-streams-polyfill

etc/web-streams-polyfill.api.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,11 @@ export class ReadableStream<R = any> implements AsyncIterable<R> {
6363
constructor(underlyingSource?: UnderlyingSource<R>, strategy?: QueuingStrategy<R>);
6464
cancel(reason?: any): Promise<void>;
6565
static from<R>(asyncIterable: Iterable<R> | AsyncIterable<R> | ReadableStreamLike<R>): ReadableStream<R>;
66-
getReader({ mode }: {
66+
getReader(options: {
6767
mode: 'byob';
6868
}): ReadableStreamBYOBReader;
6969
getReader(): ReadableStreamDefaultReader<R>;
70+
getReader(options?: ReadableStreamGetReaderOptions | undefined): ReadableStreamReader<R>;
7071
get locked(): boolean;
7172
pipeThrough<RS extends ReadableStream>(transform: {
7273
readable: RS;
@@ -113,7 +114,7 @@ export type ReadableStreamBYOBReadResult<T extends ArrayBufferView> = {
113114
export class ReadableStreamBYOBRequest {
114115
respond(bytesWritten: number): void;
115116
respondWithNewView(view: ArrayBufferView): void;
116-
get view(): ArrayBufferView | null;
117+
get view(): ArrayBufferView<ArrayBuffer> | null;
117118
}
118119

119120
// @public
@@ -151,9 +152,15 @@ export type ReadableStreamDefaultReadResult<T> = {
151152
value: T;
152153
} | {
153154
done: true;
154-
value?: undefined;
155+
value: undefined;
155156
};
156157

158+
// @public
159+
export interface ReadableStreamGetReaderOptions {
160+
// (undocumented)
161+
mode?: 'byob';
162+
}
163+
157164
// @public
158165
export interface ReadableStreamIteratorOptions {
159166
// (undocumented)
@@ -168,6 +175,9 @@ export interface ReadableStreamLike<R = any> {
168175
readonly locked: boolean;
169176
}
170177

178+
// @public
179+
export type ReadableStreamReader<R> = ReadableStreamDefaultReader<R> | ReadableStreamBYOBReader;
180+
171181
// @public
172182
export interface ReadableWritablePair<R, W> {
173183
// (undocumented)

0 commit comments

Comments
 (0)