From df903c1469f037c0695545ade786d4bfcfabf5ab Mon Sep 17 00:00:00 2001 From: shrimbly Date: Thu, 12 Mar 2026 21:40:36 +1300 Subject: [PATCH] fix: clean up pending thumbnail map on rejection to prevent stale entries Move removePending to .finally() so it runs on both resolve and reject, preventing stale rejected promises from accumulating in the pending map. Co-Authored-By: Claude Opus 4.6 --- src/hooks/useAdaptiveImageSrc.ts | 35 ++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/hooks/useAdaptiveImageSrc.ts b/src/hooks/useAdaptiveImageSrc.ts index 63d61ecc..93a019d7 100644 --- a/src/hooks/useAdaptiveImageSrc.ts +++ b/src/hooks/useAdaptiveImageSrc.ts @@ -66,27 +66,32 @@ export function useAdaptiveImageSrc( // Check if generation is already in progress const existing = getPending(fullSrc); if (existing) { - existing.then((thumb) => { - if (prevSrcRef.current === fullSrc) { - setThumbnailSrc(thumb); - } - }); + existing + .then((thumb) => { + if (prevSrcRef.current === fullSrc) { + setThumbnailSrc(thumb); + } + }) + .catch(() => {}); return; } // Generate thumbnail - const promise = generateThumbnail(fullSrc).then((thumb) => { - setThumbnail(fullSrc, thumb); - removePending(fullSrc); - return thumb; - }); + const promise = generateThumbnail(fullSrc) + .then((thumb) => { + setThumbnail(fullSrc, thumb); + if (prevSrcRef.current === fullSrc) { + setThumbnailSrc(thumb); + } + return thumb; + }) + .finally(() => { + removePending(fullSrc); + }); setPending(fullSrc, promise); - promise.then((thumb) => { - if (prevSrcRef.current === fullSrc) { - setThumbnailSrc(thumb); - } - }); + // Suppress unhandled rejection — fullSrc falls back gracefully + promise.catch(() => {}); }, [fullSrc]); if (!fullSrc) return null;