'use client'; import { useEffect, useRef } from 'react'; const PLACEHOLDER = '/images/product-placeholder.svg'; interface ProductImageProps { src?: string | null; alt: string; className?: string; width?: number; height?: number; loading?: 'lazy' | 'eager'; } export function ProductImage({ src, alt, className, width, height, loading }: ProductImageProps) { const hasErrored = useRef(false); // Reset the loop guard whenever src changes (e.g. navigating between products) useEffect(() => { hasErrored.current = false; }, [src]); function handleError(e: React.SyntheticEvent) { if (hasErrored.current) return; hasErrored.current = true; e.currentTarget.src = PLACEHOLDER; } return ( // eslint-disable-next-line @next/next/no-img-element {alt} ); }