File tree Expand file tree Collapse file tree 3 files changed +33
-10
lines changed Expand file tree Collapse file tree 3 files changed +33
-10
lines changed Original file line number Diff line number Diff line change @@ -16,11 +16,29 @@ export default function DocImage({
1616 return null ;
1717 }
1818
19- // Next.js Image component only supports images from the public folder
20- // or from a remote server with properly configured domain
19+ // Handle external images early - pass through without processing
2120 if ( src . startsWith ( 'http' ) ) {
22- // eslint-disable-next-line @next/next/no-img-element
23- return < img src = { src } { ...props } /> ;
21+ // Use provided props or defaults for external images
22+ const width = typeof propsWidth === 'number'
23+ ? propsWidth
24+ : typeof propsWidth === 'string'
25+ ? parseInt ( propsWidth , 10 ) || 800
26+ : 800 ;
27+ const height = typeof propsHeight === 'number'
28+ ? propsHeight
29+ : typeof propsHeight === 'string'
30+ ? parseInt ( propsHeight , 10 ) || 600
31+ : 600 ;
32+
33+ return (
34+ < DocImageClient
35+ src = { src }
36+ imgPath = { src } // For external images, imgPath should be the same as src
37+ width = { width }
38+ height = { height }
39+ { ...props }
40+ />
41+ ) ;
2442 }
2543
2644 // If the image src is not an absolute URL, we assume it's a relative path
Original file line number Diff line number Diff line change @@ -30,11 +30,12 @@ export function DocImageClient({
3030
3131 // For external images or invalid dimensions, fall back to regular img tag
3232 if ( src . startsWith ( 'http' ) || ! isValidDimensions ) {
33- const handleClick = ( e : React . MouseEvent ) => {
34- // If Ctrl/Cmd+click, open image in new tab
35- if ( e . ctrlKey || e . metaKey ) {
36- window . open ( imgPath , '_blank' , 'noreferrer' ) ;
37- return ;
33+ const handleClick = ( ) => {
34+ // Always open image in new tab
35+ const url = src . startsWith ( 'http' ) ? src : imgPath ;
36+ const newWindow = window . open ( url , '_blank' ) ;
37+ if ( newWindow ) {
38+ newWindow . opener = null ; // Security: prevent opener access
3839 }
3940 } ;
4041
Original file line number Diff line number Diff line change @@ -27,7 +27,11 @@ export function ImageLightbox({
2727 const handleClick = ( e : React . MouseEvent ) => {
2828 // If Ctrl/Cmd+click, open image in new tab
2929 if ( e . ctrlKey || e . metaKey ) {
30- window . open ( imgPath , '_blank' , 'noreferrer' ) ;
30+ const url = src . startsWith ( 'http' ) ? src : imgPath ;
31+ const newWindow = window . open ( url , '_blank' ) ;
32+ if ( newWindow ) {
33+ newWindow . opener = null ; // Security: prevent opener access
34+ }
3135 return ;
3236 }
3337 // Normal click - open lightbox
You can’t perform that action at this time.
0 commit comments