Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions website/src/components/avatar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useEffect, useRef, useState } from 'react';

export function Avatar({ src, className }: { src: string; className: string }) {
const imageRef = useRef<HTMLImageElement>(null);
const [visibleSrc, setVisibleSrc] = useState<string | null>(null);

useEffect(() => {
const image = imageRef.current;
if (!image) return;

// Native lazy loading can fetch images far outside the viewport.
const observer = new IntersectionObserver(
([entry]) => {
if (entry?.isIntersecting) {
setVisibleSrc(src);
observer.disconnect();
}
},
{ rootMargin: '200px 0px' },
);
observer.observe(image);
return () => observer.disconnect();
}, [src]);

return (
<img
ref={imageRef}
src={visibleSrc === src ? src : undefined}
alt=""
width="28"
height="28"
loading="lazy"
className={className}
/>
);
}
7 changes: 2 additions & 5 deletions website/src/components/timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from 'lucide-react';
import { createPortal } from 'react-dom';

import { Avatar } from '@/components/avatar';
import { Badge } from '@/components/ui/badge';
import {
Select,
Expand Down Expand Up @@ -407,12 +408,8 @@ export function Timeline({
/>
<div className="flex items-start gap-3">
{avatarUrl ? (
<img
<Avatar
src={avatarUrl}
alt=""
width="28"
height="28"
loading="lazy"
className={cn(
'size-7 flex-none bg-white/5 ring-1 ring-border',
isRenovateBot ? 'rounded-md' : 'rounded-full',
Expand Down
Loading