Skip to content

Commit 22b45b4

Browse files
Fix image loading for svg error
1 parent 5c8ee89 commit 22b45b4

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

components/imageViewer.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@ import { ArrowsPointingInIcon, ArrowsPointingOutIcon } from "@heroicons/react/24
1010
const ImageViewer = ({ image }: { image?: SanityImageObject }) => {
1111
const [openImage, toggleOpenImage] = useToggle()
1212

13+
if (!image?.asset) return null
14+
15+
// ✅ Detect if image is an SVG (Sanity asset ref ends in -svg)
16+
const isSVG = image.asset._ref?.includes("-svg")
17+
18+
const imageUrl = urlFor(image).url()
19+
20+
if (isSVG) {
21+
return (
22+
<img
23+
src={imageUrl}
24+
alt={image.alt ?? ""}
25+
className="w-full object-contain max-h-[500px]"
26+
/>
27+
)
28+
}
29+
1330
const showFullImage = (image ? getImageDimensions(urlFor(image).url()).aspectRatio : 0) > 16 / 7
1431

1532
return (

0 commit comments

Comments
 (0)