Skip to content

Commit

Permalink
cancel fetch early
Browse files Browse the repository at this point in the history
sadly this only seems to work on gifs, but it seems like good practice to commit it
  • Loading branch information
marcustyphoon committed Jan 29, 2025
1 parent ed1cecf commit f011b43
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/features/accesskit/disable_gifs.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ const isAnimated = memoize(async (sourceUrl) => {
if (typeof ImageDecoder !== 'function') return isAnimatedDefault;
/* globals ImageDecoder */

const response = await fetch(sourceUrl);
const controller = new AbortController();
const response = await fetch(sourceUrl, { signal: controller.signal });

const contentType = response.headers.get('Content-Type');
const supported = await ImageDecoder.isTypeSupported(contentType);
Expand All @@ -89,6 +90,7 @@ const isAnimated = memoize(async (sourceUrl) => {
preferAnimation: true
});
await decoder.decode();
controller.abort();
return decoder.tracks.selectedTrack.animated;
});

Expand Down

0 comments on commit f011b43

Please sign in to comment.