@@ -13,10 +13,10 @@ interface ImageLightboxProps
1313 'ref' | 'src' | 'width' | 'height' | 'alt'
1414 > {
1515 alt : string ;
16- height : number ;
1716 imgPath : string ;
1817 src : string ;
19- width : number ;
18+ height ?: number ;
19+ width ?: number ;
2020}
2121
2222export function ImageLightbox ( {
@@ -31,8 +31,17 @@ export function ImageLightbox({
3131} : ImageLightboxProps ) {
3232 const [ open , setOpen ] = useState ( false ) ;
3333
34- // Check if dimensions are valid (not NaN) for Next.js Image
35- const isValidDimensions = ! isNaN ( width ) && ! isNaN ( height ) && width > 0 && height > 0 ;
34+ // Check if we should use Next.js Image or regular img
35+ // Use Next.js Image for internal images with valid dimensions
36+ // Use regular img for external images or when dimensions are invalid/missing
37+ const shouldUseNextImage =
38+ ! src . startsWith ( 'http' ) && // Internal image
39+ width != null &&
40+ height != null && // Dimensions provided
41+ ! isNaN ( width ) &&
42+ ! isNaN ( height ) && // Valid numbers
43+ width > 0 &&
44+ height > 0 ; // Positive values
3645
3746 const handleClick = ( e : React . MouseEvent ) => {
3847 // If Ctrl/Cmd+click, open image in new tab
@@ -70,14 +79,14 @@ export function ImageLightbox({
7079 // Next.js Image has stricter typing for certain props like 'placeholder'
7180 const { placeholder : _placeholder , ...imageCompatibleProps } = props ;
7281
73- // Render the appropriate image component based on dimension validity
82+ // Render the appropriate image component
7483 const renderImage = ( ) => {
75- if ( isValidDimensions ) {
84+ if ( shouldUseNextImage ) {
7685 return (
7786 < Image
7887 src = { src }
79- width = { width }
80- height = { height }
88+ width = { width ! }
89+ height = { height ! }
8190 style = { {
8291 width : '100%' ,
8392 height : 'auto' ,
@@ -131,12 +140,12 @@ export function ImageLightbox({
131140
132141 { /* Image container */ }
133142 < div className = "relative flex items-center justify-center" >
134- { isValidDimensions ? (
143+ { shouldUseNextImage ? (
135144 < Image
136145 src = { src }
137146 alt = { alt }
138- width = { width }
139- height = { height }
147+ width = { width ! }
148+ height = { height ! }
140149 className = "max-h-[90vh] max-w-[90vw] object-contain"
141150 style = { {
142151 width : 'auto' ,
0 commit comments