@@ -127,15 +127,15 @@ export default function IdealImage(
127
127
const highestResSrc = img . src . images [ img . src . images . length - 1 ] ;
128
128
129
129
const [ isZoomed , setIsZoomed ] = useState ( false ) ;
130
- const [ isLoaded , setIsLoaded ] = useState ( true ) ;
130
+ const [ isLoaded , setIsLoaded ] = useState ( false ) ;
131
131
const imageRef = useRef < HTMLDivElement > ( null ) ;
132
132
133
133
useEffect ( ( ) => {
134
134
if ( ! imageRef . current ) return ;
135
135
136
136
const observer = new MutationObserver ( ( ) => {
137
137
const imgElement = imageRef . current ?. querySelector ( "img" ) ;
138
- if ( imgElement && imgElement . complete ) {
138
+ if ( imgElement && imgElement . src . endsWith ( currentImage . path ! ) ) {
139
139
setIsLoaded ( true ) ;
140
140
observer . disconnect ( ) ;
141
141
}
@@ -202,16 +202,22 @@ export default function IdealImage(
202
202
style = { imageStyles }
203
203
/>
204
204
) ;
205
-
205
+ let connection = null ;
206
+ if ( "connection" in navigator ) {
207
+ connection =
208
+ navigator . connection ||
209
+ navigator . mozConnection ||
210
+ navigator . webkitConnection ;
211
+ }
206
212
return (
207
213
< div style = { containerStyles } >
208
214
{ /* Zoomed Image */ }
209
- < ControlledZoom
210
- isZoomed = { isZoomed }
211
- onZoomChange = { handleZoomChange }
212
- classDialog = { ` ${ styles . customZoom } ${ background == "white" ? styles . customWhiteZoom : "" } ` }
213
- >
214
- { isLoaded && (
215
+ { connection && connection . effectiveType == "4g" && (
216
+ < ControlledZoom
217
+ isZoomed = { isZoomed }
218
+ onZoomChange = { handleZoomChange }
219
+ classDialog = { ` ${ styles . customZoom } ${ background == "white" ? styles . customWhiteZoom : "" } ` }
220
+ >
215
221
< img
216
222
src = { highestResSrc . path }
217
223
alt = { `${ alt } - Zoomed` }
@@ -222,16 +228,21 @@ export default function IdealImage(
222
228
visibility : isZoomed ? "visible" : "hidden" ,
223
229
} }
224
230
/>
225
- ) }
226
- </ ControlledZoom >
227
-
228
- { /* Clickable IdealImage (Hidden when zoomed) */ }
231
+ </ ControlledZoom >
232
+ ) }
229
233
< div
230
234
ref = { imageRef }
231
- onClick = { ( ) => isLoaded && setIsZoomed ( true ) }
235
+ onClick = { ( ) =>
236
+ connection &&
237
+ connection . effectiveType == "4g" &&
238
+ isLoaded &&
239
+ setIsZoomed ( true )
240
+ }
232
241
style = { {
233
- cursor : isLoaded ? "zoom-in" : "default" ,
234
- visibility : isZoomed ? "hidden" : "visible" ,
242
+ cursor :
243
+ connection && connection . effectiveType == "4g" && isLoaded
244
+ ? "zoom-in"
245
+ : "default" ,
235
246
} }
236
247
>
237
248
{ img_component }
0 commit comments