Open revuwem opened 10 months ago
It looks like the useImageLoadingStatus
in Avatar.tsx
doesn't handle the lazy
attribute for created image.
function useImageLoadingStatus(src?: string) {
const [loadingStatus, setLoadingStatus] = React.useState<ImageLoadingStatus>('idle');
useLayoutEffect(() => {
if (!src) {
setLoadingStatus('error');
return;
}
let isMounted = true;
const image = new window.Image();
const updateStatus = (status: ImageLoadingStatus) => () => {
if (!isMounted) return;
setLoadingStatus(status);
};
setLoadingStatus('loading');
image.onload = updateStatus('loaded');
image.onerror = updateStatus('error');
image.src = src;
return () => {
isMounted = false;
};
}, [src]);
return loadingStatus;
}
Bug report
Current Behavior
The
<Avatar.Image />
acceptsloading="lazy"
but it actually has no effect, the image loads on page loading time.Expected behavior
The
<Avatar.Image />
withloading="lazy"
provided loads image only when user navigates to it.Your environment