Files
buzz-sheet/components/ui/resilient-image.tsx
T
gunshiz 5ebe4db78c
CI / Verify (push) Successful in 1m33s
CI / Build immutable images and deploy (push) Successful in 3m17s
fix(images) : fall back to original CDN file without transformations
2026-10-06 15:17:43 +07:00

26 lines
713 B
TypeScript

"use client";
import NextImage, { type ImageProps } from "next/image";
import { useState } from "react";
const CDN_ORIGIN = "https://buzz-cdn.astrxl.dev";
export default function ResilientImage({ src, unoptimized, onError, ...props }: ImageProps) {
const [failedSource, setFailedSource] = useState<string | null>(null);
const useOriginal = typeof src === "string" && failedSource === src;
return (
<NextImage
{...props}
src={src}
unoptimized={unoptimized || useOriginal}
onError={(event) => {
if (!useOriginal && typeof src === "string" && src.startsWith(`${CDN_ORIGIN}/`)) {
setFailedSource(src);
}
onError?.(event);
}}
/>
);
}