Closed tpluscode closed 4 years ago
And speaking of whatwg-fetch, why doesn't fetch-ponyfill use native fetch if the browser implements it?
The answer to your second question is also inadvertently the answer to this issue. The behaviour is intentional because this is a ponyfill (not a polyfill). It’s always meant to ignore the built-in implementation (when available) and as a side effect you’ll get a fresh implementation of fetch each time you call the function in this module.
For the behaviour you want you should probably use whatwg-fetch
.
More on ponyfills: https://github.com/sindresorhus/ponyfill
Thank you for answering the second question, but pureness does not explain why a different Headers
class should be returned on every import. The problem is the bootstrap function which this package exports
Of course, I might take it up with whatwg-fetch
to alter how the instances are recognised but I think that the current behavior is against principle of least surprise.
Ah, and Node support is the reason not to use whatwg-fetch
directly...
The title may seem a little off, but the problem I found is that importing
fetch-ponyfill
multiple times run the bootstrapper for each of those imports.Something like above will create two equal, but not the same
Headers
classes. This makes it impossible to create one headers in stance from the other because it is no recognized by theinstanceof
check which whatwg-fetch doesTry this sandbox: https://codesandbox.io/s/fervent-fermi-5iews?file=/src/index.js