Skip to content

Fix cached images not appearing in ImageWithFallback - #8923

Merged
4ian merged 2 commits into
masterfrom
fix/cached-images-imagewitfallback
Aug 4, 2026
Merged

Fix cached images not appearing in ImageWithFallback#8923
4ian merged 2 commits into
masterfrom
fix/cached-images-imagewitfallback

Conversation

@Bouh

@Bouh Bouh commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Fix a race condition because of the cache.
Images loaded from browser cache don't trigger the onLoad event, causing opacity to remain at 0 and images to be invisible.

<CorsAwareImage
{...props}
src={src}
alt={alt}
// Keep the image invisible until it has successfully loaded, so the
// browser's native "broken image" glyph is never shown for a fraction of
// a second before the fallback appears.
style={{
...style,
opacity: isLoaded ? (style && style.opacity) || 1 : 0,
}}
loading={loading}
onLoad={() => setIsLoaded(true)}
onError={() => setHasError(true)}
/>
);

image

Solution

Check the img.complete property to detect cached images and set isLoaded state.
Works for both fresh loads and cached images.

Images loaded from browser cache don't trigger onLoad event, causing opacity to stay at 0. Use img.complete property to detect cached images and set isLoaded state accordingly.
@Bouh
Bouh requested a review from 4ian as a code owner August 4, 2026 13:58
@4ian
4ian merged commit 6950ef4 into master Aug 4, 2026
5 of 6 checks passed
@4ian
4ian deleted the fix/cached-images-imagewitfallback branch August 4, 2026 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants