lquixada / cross-fetch

Universal WHATWG Fetch API for Node, Browsers and React Native.
MIT License
1.67k stars 104 forks source link

Is the AbortController supported in cross-fetch? #85

Closed Spiralis closed 3 years ago

Spiralis commented 3 years ago

I am using the AbortController feature (sample) in my code, and for my jest tests which uses jest-fetch-mock, the AbortController.abort() method works.

In my browser I can see that a manual test of the window.fetch works fine with the AbortController too. But, when cross-fetch is handling the fetch in the browser the abortcontroller signal is ignored - it seems.

I also see that there is no code in the cross-fetch project that deals with the abort-controller, and no issues mentioning it. I can see that the code supports setting the RequestInit.signal property though. So, I was expecting it to be passed into the window.fetch(), which I assume that cross-fetch is perhaps using under the hood - when run in the browser?

lquixada commented 3 years ago

Hi @Spiralis! Thanks for opening an issue. I couldn't reproduce the error. I've forked your code to test it: https://codesandbox.io/s/abortable-fetch-forked-89tvi?file=/src/index.js

Spiralis commented 3 years ago

Yeah. I just got it working myself. I am not able to see the problem in any way. I must have missed out on something essential, yet I am not seeing it.

But, happy to see it working :)

Spiralis commented 3 years ago

@lquixada, I think I found the reason. I believe my failing cross-fetch was v2.2.3. Since cross-fetch failed for me with the AbortController feature, I tried other alternatives - which had their own set of problems... So I reinstalled cross-fetch to give it another go - and potentially instead contribute in regards to help fixing it. With that reinstall I got v3.0.4 - which works.

I was so sure that I was on the latest cross-fetch at the time I had the problems. I was fooled after runniing a yarn upgrade-interactive, which did not prompt me to do the major v3 upgrade. Lesson learned, again... :|

But, thanks for the prompt reply. And thanks for the project. Great work :)

lquixada commented 3 years ago

@Spiralis I'm glad it worked out for you. 👍 Ps: the latest version is 3.0.6.