@@ -4,14 +4,11 @@ import Image from 'next/image';
44
55import { ImageLightbox } from './imageLightbox' ;
66
7- interface DocImageClientProps {
8- alt : string ;
7+ interface DocImageClientProps extends Omit < React . HTMLProps < HTMLImageElement > , 'ref' | 'placeholder' | 'src' | 'width' | 'height' > {
98 height : number ;
109 imgPath : string ;
1110 src : string ;
1211 width : number ;
13- className ?: string ;
14- style ?: React . CSSProperties ;
1512}
1613
1714export function DocImageClient ( {
@@ -22,6 +19,7 @@ export function DocImageClient({
2219 alt,
2320 style,
2421 className,
22+ ...props
2523} : DocImageClientProps ) {
2624 const handleContextMenu = ( e : React . MouseEvent ) => {
2725 e . preventDefault ( ) ; // Prevent default context menu
@@ -42,9 +40,32 @@ export function DocImageClient({
4240 }
4341 } ;
4442
43+ // Check if dimensions are valid (not NaN) for Next.js Image
44+ const isValidDimensions = ! isNaN ( width ) && ! isNaN ( height ) && width > 0 && height > 0 ;
45+
46+ // For external images or invalid dimensions, fall back to regular img tag
47+ if ( src . startsWith ( 'http' ) || ! isValidDimensions ) {
48+ return (
49+ < div onContextMenu = { handleContextMenu } onClick = { handleClick } >
50+ { /* eslint-disable-next-line @next/next/no-img-element */ }
51+ < img
52+ src = { src }
53+ alt = { alt ?? '' }
54+ style = { {
55+ width : '100%' ,
56+ height : 'auto' ,
57+ ...style ,
58+ } }
59+ className = { className }
60+ { ...props }
61+ />
62+ </ div >
63+ ) ;
64+ }
65+
4566 return (
4667 < div onContextMenu = { handleContextMenu } onClick = { handleClick } >
47- < ImageLightbox src = { src } alt = { alt } width = { width } height = { height } >
68+ < ImageLightbox src = { src } alt = { alt ?? '' } width = { width } height = { height } >
4869 < Image
4970 src = { src }
5071 width = { width }
@@ -55,7 +76,8 @@ export function DocImageClient({
5576 ...style ,
5677 } }
5778 className = { className }
58- alt = { alt }
79+ alt = { alt ?? '' }
80+ { ...props }
5981 />
6082 </ ImageLightbox >
6183 </ div >
0 commit comments