Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix browser support #122

Merged
merged 1 commit into from
Mar 15, 2024
Merged

Fix browser support #122

merged 1 commit into from
Mar 15, 2024

Conversation

ehmicky
Copy link
Collaborator

@ehmicky ehmicky commented Mar 14, 2024

Fixes #116.

@ehmicky ehmicky marked this pull request as draft March 14, 2024 22:45
@ehmicky ehmicky force-pushed the web-stream branch 2 times, most recently from 65e9334 to 95e5f30 Compare March 14, 2024 22:50
@ehmicky ehmicky marked this pull request as ready for review March 14, 2024 22:51
@ehmicky
Copy link
Collaborator Author

ehmicky commented Mar 14, 2024

Fixed the PR. Ready for review.

@@ -43,6 +43,7 @@
"concat"
],
"dependencies": {
"@sec-ant/readable-stream": "^0.3.2",
Copy link
Collaborator Author

@ehmicky ehmicky Mar 14, 2024

Choose a reason for hiding this comment

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

The dependency is quite small: ~250 lines, no dependencies.

I looked into each implementation, and its behavior is almost identical to both the Node.js implementation, and the 400KB official polyfill for web streams.

// Use this library as a ponyfill instead of a polyfill.
// I.e. avoid modifying global variables.
// We can remove this once https://github.com/Sec-ant/readable-stream/issues/2 is fixed
if (prototype[Symbol.asyncIterator] === undefined && prototype.values === undefined) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This condition is always false on Node, Firefox and Chrome >124. On those platforms, this file is a noop.

@@ -0,0 +1,13 @@
export const ponyfill = {};
Copy link
Collaborator Author

@ehmicky ehmicky Mar 14, 2024

Choose a reason for hiding this comment

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

@sindresorhus Didn't you coin that term? Happy to spread it! 🦄

await import('@sec-ant/readable-stream');
ponyfill.asyncIterator = prototype[Symbol.asyncIterator];
delete prototype[Symbol.asyncIterator];
delete prototype.values;
Copy link
Collaborator Author

@ehmicky ehmicky Mar 14, 2024

Choose a reason for hiding this comment

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

Not polyfilling ensures we don't get issues for users that use the "official" web streams polyfill. Also, this avoids any global side effects.

The author of the polyfill is working on turning it into a ponyfill. When that happens, we can remove this file entirely.

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.

getStreamAsArrayBuffer from a ReadableStream fails on Chrome, but works on FF.
2 participants