import Image, { type ImageProps } from 'next/image'; import { OPTIMIZED_IMAGE_HOSTS } from '@/core/lib/image-hosts'; const OPTIMIZED_HOSTS = new Set(OPTIMIZED_IMAGE_HOSTS); function isOptimizedHost(src: ImageProps['src']): boolean { if (typeof src !== 'string') return true; // StaticImageData — always local try { return OPTIMIZED_HOSTS.has(new URL(src).hostname); } catch { return false; } } /** * Drop-in `next/image` replacement for Brainerce-sourced images (product * photos, blog covers). Uploaded images get re-hosted onto cdn.brainerce.com * by the backend's async image-import pipeline, but a product/variant can * still carry a raw upstream-merchant URL while mid-import, or if that job * failed. next/image throws if `src`'s host isn't in `images.remotePatterns`, * so any host outside our known CDN falls back to `unoptimized` — an * unresized, direct-from-origin fetch — instead of crashing the page. */ export function CdnImage({ unoptimized, ...props }: ImageProps) { return ; }