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

It is not a ponyfill! #184

Open
iegik opened this issue Jun 14, 2024 · 2 comments
Open

It is not a ponyfill! #184

iegik opened this issue Jun 14, 2024 · 2 comments

Comments

@iegik
Copy link

iegik commented Jun 14, 2024

Whats the difference between Ponyfill and Polyfill?

Polyfill - checks if functionality is not available and add it:

if (!String.prototype.trim) String.prototype.trim = ...

Ponyfill - just the adds own same functionality:

function trim(){...}
import { trim } from '...'

What about whatwg-fetch on this project?

whatwg-fetch is Polyfill, but on acts like Ponyfill. Why?

WARNING: On the build phase global this is passed without fetch, so it hardcoded to overwrite the fetch function!!!!
https://github.com/lquixada/cross-fetch/blob/v4.x/rollup.config.js

This will cause some unexpected behaviour of the fetch function.

For example, it throws an Error when request is aborted. Should it?

Abort should not throw the error:

https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API

It returns a Promise that resolves to the Response to that request — as soon as the server responds with headers — even if the server response is an HTTP error status. 

At the heart of Fetch are the Interface abstractions of HTTP Requests, Responses, and Headers, along with a fetch() method for initiating asynchronous resource requests

Fetch takes the asynchronous nature of such requests one step further. The API is completely Promise-based
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Basic_concepts#in_a_nutshell

https://xhr.spec.whatwg.org/#the-abort()-method


In other words, it should fire the 'abort' event and cancels the request and DO NOT throw an error. Because fetch is asynchronous*

fetch is asynchronous, based on Promise, but resolved only when response is received.

@iegik
Copy link
Author

iegik commented Jun 14, 2024

Related: jasonkuhrt/graphql-request#212

@iegik
Copy link
Author

iegik commented Jun 14, 2024

#172

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

1 participant