Adjust image fallback cache behavior

This commit is contained in:
Sam Becker 2025-04-27 22:43:27 -05:00
parent 84ff9885cc
commit 1894d710ef
2 changed files with 10 additions and 10 deletions

View File

@ -32,15 +32,10 @@ export default function ImageWithFallback({
const imgRef = useRef<HTMLImageElement>(null);
useEffect(() => {
const timeout = setTimeout(
// Prevent blank flash by waiting for image to load
() => setWasCached(
Boolean(imgRef.current?.complete) &&
(imgRef.current?.naturalWidth ?? 0) > 0,
),
50,
setWasCached(
Boolean(imgRef.current?.complete) &&
(imgRef.current?.naturalWidth ?? 0) > 0,
);
return () => clearTimeout(timeout);
}, []);
useEffect(() => {
@ -108,4 +103,4 @@ export default function ImageWithFallback({
</div>
</div>
);
}
}

View File

@ -27,6 +27,7 @@ import { INITIAL_UPLOAD_STATE, UploadState } from '@/admin/upload';
import { RecipeProps } from '@/recipe';
import { getCountsForCategoriesCachedAction } from '@/category/actions';
import { nanoid } from 'nanoid';
import { toastSuccess } from '@/toast';
export default function AppStateProvider({
children,
@ -169,7 +170,11 @@ export default function AppStateProvider({
setUserEmail(undefined);
setUserEmailEager(undefined);
clearAuthEmailCookie();
if (isPathProtected(pathname)) { router.push(PATH_ROOT); }
if (isPathProtected(pathname)) {
router.push(PATH_ROOT);
} else {
toastSuccess('Signed out');
}
}, [router, pathname]);
// Returns false when upload is cancelled