@@ -4,14 +4,11 @@ import Image from 'next/image';
4
4
5
5
import { ImageLightbox } from './imageLightbox' ;
6
6
7
- interface DocImageClientProps {
8
- alt : string ;
7
+ interface DocImageClientProps extends Omit < React . HTMLProps < HTMLImageElement > , 'ref' | 'placeholder' | 'src' | 'width' | 'height' > {
9
8
height : number ;
10
9
imgPath : string ;
11
10
src : string ;
12
11
width : number ;
13
- className ?: string ;
14
- style ?: React . CSSProperties ;
15
12
}
16
13
17
14
export function DocImageClient ( {
@@ -22,6 +19,7 @@ export function DocImageClient({
22
19
alt,
23
20
style,
24
21
className,
22
+ ...props
25
23
} : DocImageClientProps ) {
26
24
const handleContextMenu = ( e : React . MouseEvent ) => {
27
25
e . preventDefault ( ) ; // Prevent default context menu
@@ -42,9 +40,32 @@ export function DocImageClient({
42
40
}
43
41
} ;
44
42
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
+
45
66
return (
46
67
< 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 } >
48
69
< Image
49
70
src = { src }
50
71
width = { width }
@@ -55,7 +76,8 @@ export function DocImageClient({
55
76
...style ,
56
77
} }
57
78
className = { className }
58
- alt = { alt }
79
+ alt = { alt ?? '' }
80
+ { ...props }
59
81
/>
60
82
</ ImageLightbox >
61
83
</ div >
0 commit comments