Handle platforms where AbortController is not supported, instead of asking for (ineffective) polyfills #9049
Unanswered
peaBerberian
asked this question in
Ideas
Replies: 1 comment 1 reply
-
We only target platforms that support I think the best thing you can do is use a polyfill that actually works, or make your check detect such polyfills and don’t use |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
tl;dr: The "idea" I'm proposing here is to actually fix an issue in multiple popular media players that is provoked indirectly by a requirement of
tanstack-query
: the presence of theAbortController
API on the platform.Sadly all
AbortController
polyfills that we know of are not really "functional", in that they do not provoke the expected behavior on thefetch
API, its principal consumer, including any of them in an application has an important negative effect on media players.I'm thus asking for
tanstack-query
to allowAbortController
to not be defined on the current platform.Explanation:
I'm a library developer for a web media player.
An application depending on this player was having multiple issues after relying on tanstack-query.
They target some old devices which have access to the
fetch
API, but not to theAbortController
API (e.g. smart TVs, game consoles).Because they saw errors about that object being
undefined
when relying ontanstack-query
, they looked at thetanstack-query
API documentation on the subject which proposes, and link to, severalAbortController
polyfills.They then imported one of those, saw that
tanstack-query
worked, and then thought that everything was OK.But actually those polyfills have a big downside that is difficult to see at first, they don't actually provoke "real" cancellation on the
fetch
API, which is the main consumer for that API. In a way they don't really fulfill their main goal.This creates an important problem for some library developers, including those developing media players, like me.
We frequently have large chunks of media data to download and we thus rely on a functional cancellation mechanism to ensure a good experience. Let's for example imagine that the user's bandwidth drastically drops while loading 4k UHD video content: here we want to be able to cancel the request and request a lower video quality instead.
Because cancellation is very important, we check that both
fetch
andAbortController
are available on the platform before choosing that API. If it's not, we fallback on anXmlHttpRequest
(we preferfetch
for other reasons, but cancellation is very important for us).This is the case in our player, but also in the much popular
shaka-player
andhls.js
players, which all have similar logic where we check both forfetch
andAbortController
and if any of them is not defined, we fallback to an XHR.Due to an
AbortController
polyfill being imported, all those players will now think they are able to rely on a cancellablefetch
, and thus lead to a worse experience for end users, without application developers noticing right away.I'm talking only about media players because that's what I know, but I'm sure there are other use cases where a functional
AbortController
+fetch
API is important.Idea:
We ask applications to avoid including an
AbortController
polyfill for now, but doing this prevent them from usingtanstack-query
.What I propose for
tanstack-query is to still work even if
AbortController` is not available in global scope, or perhaps to let the application define one if that would be preferable for you.Beta Was this translation helpful? Give feedback.
All reactions