From b21aa5f8821c3daf37949d59e28627cb3460a43f Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Tue, 24 Jun 2025 18:05:42 -0500 Subject: [PATCH] Revert fallback strat --- src/components/image/ImageWithFallback.tsx | 23 +++++++++------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/components/image/ImageWithFallback.tsx b/src/components/image/ImageWithFallback.tsx index b2e8dc06..a2c4d16f 100644 --- a/src/components/image/ImageWithFallback.tsx +++ b/src/components/image/ImageWithFallback.tsx @@ -25,9 +25,7 @@ export default function ImageWithFallback({ areAdminDebugToolsEnabled, } = useAppState(); - const hasLoadedRef = useRef(false); - const wasCachedRef = useRef(true); - + const [wasCached, setWasCached] = useState(true); const [isLoading, setIsLoading] = useState(true); const [didError, setDidError] = useState(false); @@ -40,25 +38,22 @@ export default function ImageWithFallback({ const refFallback = useRef(null); useEffect(() => { - if (!hasLoadedRef.current) { - wasCachedRef.current = ( - Boolean(refImage.current?.complete) && - (refImage.current?.naturalWidth ?? 0) > 0 - ); - hasLoadedRef.current = true; - } + setWasCached( + Boolean(refImage.current?.complete) && + (refImage.current?.naturalWidth ?? 0) > 0, + ); }, []); const shouldDebugFallbackTiming = areAdminDebugToolsEnabled && debug; const showFallback = - !wasCachedRef.current && + !wasCached && !hideFallback; if (shouldDebugFallbackTiming) { console.log({ isLoading, - wasCached: wasCachedRef.current, + wasCached, hideFallback, showFallback, }); @@ -156,7 +151,7 @@ export default function ImageWithFallback({ (showFallback || shouldDebugImageFallbacks) && 'transition-opacity duration-300 ease-in', !(BLUR_ENABLED && blurDataURL) && 'bg-main', - ((isLoading && !wasCachedRef.current) || shouldDebugImageFallbacks) + (isLoading || shouldDebugImageFallbacks) ? 'opacity-100' : 'opacity-0', )} @@ -177,4 +172,4 @@ export default function ImageWithFallback({ ); -} +} \ No newline at end of file