diff --git a/src/base/components/SpinnerImage.tsx b/src/base/components/SpinnerImage.tsx index bf950145..f364bfc3 100644 --- a/src/base/components/SpinnerImage.tsx +++ b/src/base/components/SpinnerImage.tsx @@ -119,12 +119,18 @@ export const SpinnerImage = ({ ref, ...props }: SpinnerImageProps) => { return () => {}; } + let isAborted = false; let imageRequest: ImageRequest = { response: Promise.resolve(''), cleanup: noOp, abortRequest: noOp, fromCache: false, }; + const abortRequest = () => { + isAborted = true; + imageRequest.cleanup(); + imageRequest.abortRequest(new Error('Component was unmounted')); + }; const fetchImage = async () => { try { imageRequest = await requestManager.requestImage(src, { @@ -135,6 +141,12 @@ export const SpinnerImage = ({ ref, ...props }: SpinnerImageProps) => { ignoreQueue, }); + // In case the request got aborted before it was queued, the abort was called against the "default noop" function and did nothing. + // Thus, abort again to ensure that the actual queued request gets aborted. + if (isAborted) { + abortRequest(); + } + if (!imageRequest.fromCache) { updateImageState(true); } @@ -153,8 +165,7 @@ export const SpinnerImage = ({ ref, ...props }: SpinnerImageProps) => { fetchImage().catch(() => {}); return () => { - imageRequest.cleanup(); - imageRequest.abortRequest(new Error('Component was unmounted')); + abortRequest(); }; }, [src, imgLoadRetryKey, retryKeyPrefix, showMissingImageIcon, shouldLoad]);