@@ -127,15 +127,15 @@ export default function IdealImage(
127127 const highestResSrc = img . src . images [ img . src . images . length - 1 ] ;
128128
129129 const [ isZoomed , setIsZoomed ] = useState ( false ) ;
130- const [ isLoaded , setIsLoaded ] = useState ( true ) ;
130+ const [ isLoaded , setIsLoaded ] = useState ( false ) ;
131131 const imageRef = useRef < HTMLDivElement > ( null ) ;
132132
133133 useEffect ( ( ) => {
134134 if ( ! imageRef . current ) return ;
135135
136136 const observer = new MutationObserver ( ( ) => {
137137 const imgElement = imageRef . current ?. querySelector ( "img" ) ;
138- if ( imgElement && imgElement . complete ) {
138+ if ( imgElement && imgElement . src . endsWith ( currentImage . path ! ) ) {
139139 setIsLoaded ( true ) ;
140140 observer . disconnect ( ) ;
141141 }
@@ -202,16 +202,22 @@ export default function IdealImage(
202202 style = { imageStyles }
203203 />
204204 ) ;
205-
205+ let connection = null ;
206+ if ( "connection" in navigator ) {
207+ connection =
208+ navigator . connection ||
209+ navigator . mozConnection ||
210+ navigator . webkitConnection ;
211+ }
206212 return (
207213 < div style = { containerStyles } >
208214 { /* 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+ >
215221 < img
216222 src = { highestResSrc . path }
217223 alt = { `${ alt } - Zoomed` }
@@ -222,16 +228,21 @@ export default function IdealImage(
222228 visibility : isZoomed ? "visible" : "hidden" ,
223229 } }
224230 />
225- ) }
226- </ ControlledZoom >
227-
228- { /* Clickable IdealImage (Hidden when zoomed) */ }
231+ </ ControlledZoom >
232+ ) }
229233 < div
230234 ref = { imageRef }
231- onClick = { ( ) => isLoaded && setIsZoomed ( true ) }
235+ onClick = { ( ) =>
236+ connection &&
237+ connection . effectiveType == "4g" &&
238+ isLoaded &&
239+ setIsZoomed ( true )
240+ }
232241 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" ,
235246 } }
236247 >
237248 { img_component }
0 commit comments