Browse Source

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 <noreply@anthropic.com>
handoff-20260429-1057
shrimbly 4 months ago
parent
commit
df903c1469
  1. 35
      src/hooks/useAdaptiveImageSrc.ts

35
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;

Loading…
Cancel
Save