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

0.31.2 - ReadableStream is missing on firefox #455

Closed
parafeu opened this issue Sep 27, 2022 · 2 comments
Closed

0.31.2 - ReadableStream is missing on firefox #455

parafeu opened this issue Sep 27, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@parafeu
Copy link

parafeu commented Sep 27, 2022

Hello,

Until v0.31.2, ky.js stopped working on firefox. Here is the issue.
image

The only solution was to rollback to v0.31.1.
I'm on a VueJS 3 environement using vite.js v3.1.3

@sholladay
Copy link
Collaborator

There are really two problems here:

  1. The error message is outdated and misleading. Firefox actually does have ReadableStream, but...
  2. Ky was recently updated to be much more picky about when it considers streams to be supported and that logic is now buggy.

You are using the onDownloadProgress option, which requires that the environment supports response streams. Ky used to only test for the presence of ReadableStream before proceeding, which is a pretty good heuristic for detecting support for response streams. Unfortunately, the internal supportsStreams flag has been repurposed to check for support for request streams, without properly updating the old code.

As it turns out, most browsers implement response streams but not request streams and that has been the case for years. MDN still shows no browsers support request streams, however in reality Chrome 105 does, which was released about a month ago. The Chrome team wrote about this a couple of years ago and that post has some useful details. Notably, they require that the request options have duplex: 'half' in order to send a request stream. The duplex option is very new, it doesn't even appear anywhere on MDN yet. However, it is actually in the Fetch spec at RequestInit.

After the release of Chrome 105, Ky's internal supportsStreams flag, which has historically only been used to detect support for response streams when you use onDownloadProgress, was updated to check for request stream support. When it's true, Ky will now automatically set the duplex option for you. Very cool and useful, but unfortunately that's not the only place that supportsStreams is used and that's what's causing this bug. You're using onDownloadProgress, so Ky checks supportsStreams and finds that it's false, so it incorrectly thinks that response streams aren't supported, which would mean it cannot support onDownloadProgress, and thus it throws an error.

To be clear: the supportsStreams flag now requires that request streams are supported (again only Chrome has this as of now), but then it checks that flag even if you're just trying to use response streams via onDownloadProgress.

This bug was introduced in PR #451.

@sholladay sholladay added the bug Something isn't working label Sep 28, 2022
@sindresorhus
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants