Skip to content

🎥 Make videos programmatically with React

don't throw error if GIF loading is aborted

Jonny Burgerd766bee26b22
diff --git a/packages/gif/src/GifForDevelopment.tsx b/packages/gif/src/GifForDevelopment.tsx
index 1baa8ed422..8015d5a79c 100644
--- a/packages/gif/src/GifForDevelopment.tsx
+++ b/packages/gif/src/GifForDevelopment.tsx
@@ -39,6 +39,7 @@ export const GifForDevelopment = forwardRef<
useEffect(() => {
let done = false;
+ let aborted = false;
const {prom, cancel} = parseWithWorker(resolvedSrc);
const newHandle = delayRender('Loading <Gif /> with src=' + resolvedSrc);
@@ -52,6 +53,10 @@ export const GifForDevelopment = forwardRef<
continueRender(id);
})
.catch((err) => {
+ if (aborted) {
+ return;
+ }
+
if (currentOnError.current) {
currentOnError.current(err);
} else {
@@ -61,6 +66,7 @@ export const GifForDevelopment = forwardRef<
return () => {
if (!done) {
+ aborted = true;
cancel();
}
diff --git a/packages/gif/src/GifForRendering.tsx b/packages/gif/src/GifForRendering.tsx
index 921bb7345d..cc7d2ad750 100644
--- a/packages/gif/src/GifForRendering.tsx
+++ b/packages/gif/src/GifForRendering.tsx
@@ -39,6 +39,7 @@ export const GifForRendering = forwardRef<HTMLCanvasElement, RemotionGifProps>(
useEffect(() => {
const controller = new AbortController();
let done = false;
+ let aborted = false;
const newHandle = delayRender('Loading <Gif /> with src=' + resolvedSrc);
parseGif({controller, src: resolvedSrc})
@@ -51,6 +52,10 @@ export const GifForRendering = forwardRef<HTMLCanvasElement, RemotionGifProps>(
continueRender(id);
})
.catch((err) => {
+ if (aborted) {
+ return;
+ }
+
if (currentOnError.current) {
currentOnError.current(err);
} else {
@@ -60,6 +65,7 @@ export const GifForRendering = forwardRef<HTMLCanvasElement, RemotionGifProps>(
return () => {
if (!done) {
+ aborted = true;
controller.abort();
}