@@ -5,6 +5,8 @@ import {X} from 'react-feather';
5
5
import * as Dialog from '@radix-ui/react-dialog' ;
6
6
import Image from 'next/image' ;
7
7
8
+ import { isAllowedRemoteImage } from 'sentry-docs/config/images' ;
9
+
8
10
import styles from './imageLightbox.module.scss' ;
9
11
10
12
interface ImageLightboxProps
@@ -25,6 +27,8 @@ const isExternalImage = (src: string): boolean => src.startsWith('http');
25
27
const getImageUrl = ( src : string , imgPath : string ) : string =>
26
28
isExternalImage ( src ) ? src : imgPath ;
27
29
30
+ // Using shared allowlist logic from src/config/images
31
+
28
32
type ValidDimensions = {
29
33
height : number ;
30
34
width : number ;
@@ -59,9 +63,9 @@ export function ImageLightbox({
59
63
// Check if we should use Next.js Image or regular img
60
64
// Use Next.js Image for internal images with valid dimensions
61
65
// Use regular img for external images or when dimensions are invalid/missing
62
- const validDimensions = ! isExternalImage ( src )
63
- ? getValidDimensions ( width , height )
64
- : null ;
66
+ const dimensions = getValidDimensions ( width , height ) ;
67
+ const shouldUseNextImage =
68
+ ! ! dimensions && ( ! isExternalImage ( src ) || isAllowedRemoteImage ( src ) ) ;
65
69
66
70
const handleClick = ( e : React . MouseEvent ) => {
67
71
// If Ctrl/Cmd+click, open image in new tab
@@ -101,13 +105,14 @@ export function ImageLightbox({
101
105
102
106
// Render the appropriate image component
103
107
const renderImage = ( ) => {
104
- if ( validDimensions ) {
108
+ const renderedSrc = getImageUrl ( src , imgPath ) ;
109
+ if ( shouldUseNextImage && dimensions ) {
105
110
// TypeScript knows validDimensions.width and validDimensions.height are both numbers
106
111
return (
107
112
< Image
108
- src = { src }
109
- width = { validDimensions . width }
110
- height = { validDimensions . height }
113
+ src = { renderedSrc }
114
+ width = { dimensions . width }
115
+ height = { dimensions . height }
111
116
style = { {
112
117
width : '100%' ,
113
118
height : 'auto' ,
@@ -122,8 +127,10 @@ export function ImageLightbox({
122
127
return (
123
128
/* eslint-disable-next-line @next/next/no-img-element */
124
129
< img
125
- src = { src }
130
+ src = { renderedSrc }
126
131
alt = { alt }
132
+ loading = "lazy"
133
+ decoding = "async"
127
134
style = { {
128
135
width : '100%' ,
129
136
height : 'auto' ,
@@ -161,12 +168,12 @@ export function ImageLightbox({
161
168
162
169
{ /* Image container */ }
163
170
< div className = "relative flex items-center justify-center" >
164
- { validDimensions ? (
171
+ { shouldUseNextImage && dimensions ? (
165
172
< Image
166
- src = { src }
173
+ src = { getImageUrl ( src , imgPath ) }
167
174
alt = { alt }
168
- width = { validDimensions . width }
169
- height = { validDimensions . height }
175
+ width = { dimensions . width }
176
+ height = { dimensions . height }
170
177
className = "max-h-[90vh] max-w-[90vw] object-contain"
171
178
style = { {
172
179
width : 'auto' ,
@@ -178,8 +185,10 @@ export function ImageLightbox({
178
185
) : (
179
186
/* eslint-disable-next-line @next/next/no-img-element */
180
187
< img
181
- src = { src }
188
+ src = { getImageUrl ( src , imgPath ) }
182
189
alt = { alt }
190
+ loading = "lazy"
191
+ decoding = "async"
183
192
className = "max-h-[90vh] max-w-[90vw] object-contain"
184
193
style = { {
185
194
width : 'auto' ,
0 commit comments