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

Safari's AbortController doesn't work #23

Closed
homer0 opened this issue Nov 21, 2018 · 6 comments
Closed

Safari's AbortController doesn't work #23

homer0 opened this issue Nov 21, 2018 · 6 comments

Comments

@homer0
Copy link
Contributor

homer0 commented Nov 21, 2018

First of all, this is Safari's fault.

Safari 12.0.1 supports AbortController, so the polyfill is not applied, but it doesn't do anything.

Here's a really small example I made, with a delay on the request, just in case:

import 'whatwg-fetch';
import 'abortcontroller-polyfill/dist/polyfill-patch-fetch';

const abortController = new AbortController();

const req = fetch(
  'https://jsonplaceholder.typicode.com/todos/1',
  { signal: abortController.signal }
)
.then((response) => new Promise((resolve) => {
  setTimeout(() => { resolve(response);  }, 1000);
}));

abortController.abort();

req
.then((response) => response.json())
.then((response) => console.log(response))
.catch((error) => { console.error(error); });

If you try this out on Chrome, it works like a charm, but on Safari doesn't.

Just to test if it was a Safari issue, I went to your package and removed the following check (to apply the polyfill even if there was support):

if (self.AbortController) {
  return;
}

And it worked.

Finally, the reason I'm opening the issue is to see if...

  1. Are you aware of the issue?
  2. Is possible to add an "extra check" to the browser implementation. By "extra check" I mean, you understand the real API better than me, so maybe you know what can be missing there and it can validated it before ignoring the polyfill.
  3. I missed something on the documentation... in which case I'm really sorry!.
@mo
Copy link
Owner

mo commented Nov 21, 2018

Thanks for filing this, the polyfill should be fixed so that it "just works" in Safari. I don't have time to work on this immediately but I will have a look eventually if you don't submit a PR before that. Since I havn't looked at the specifics myself yet, I don't know what the preferred solution is, but on a high level it sounds reasonable for the polyfill to feature detect the "bad AbortControll" and polyfill over it.

@homer0
Copy link
Contributor Author

homer0 commented Nov 21, 2018

I'm not sure I can help you with the detection of the "bad AbortController", but what do you think about this?

if (
  self.AbortController &&
  (!self.navigator || !self.navigator.userAgent.match(/Safari\/[\d|.]+$/)
) {
  return;
}

(I added the !self.navigator || in case it gets executed on Node)

@homer0
Copy link
Contributor Author

homer0 commented Nov 25, 2018

@mo ping; should I send a PR with that?

@mo
Copy link
Owner

mo commented Nov 25, 2018

Is the AbortController also not working in Safari versions later than 12.0.1? Can we limit the "force polyfill" to certain known-bad versions?

@mo
Copy link
Owner

mo commented Nov 25, 2018

I tried the latest technical preview and it also has the same issue. Seems like caniuse.com incorrectly claims that AbortController is supported on Safari.

@homer0 a PR with above would be great..

@mo
Copy link
Owner

mo commented Nov 29, 2018

Closing ( fixed by pull #24 )

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

No branches or pull requests

2 participants