@@ -211,22 +211,28 @@ const { state, actions, callbacks } = store(
211211 return ;
212212 }
213213
214- // Link element to preload the image.
215- const imageMetadata = state . metadata [ imageId ] ;
214+ // Sets the current image ID to preload.
215+ state . currentImageId = imageId ;
216+
217+ // Create link element to preload the image.
216218 const imageLink = document . createElement ( 'link' ) ;
217219 imageLink . rel = 'preload' ;
218220 imageLink . as = 'image' ;
219- imageLink . href = imageMetadata . uploadedSrc ;
221+ imageLink . href = state . enlargedSrc ;
220222
221- // Apply srcset if available for responsive preloading
222- const srcset = imageMetadata . lightboxSrcset ;
223+ // Apply srcset if available for responsive preloading.
224+ const srcset = state . enlargedSrcset ;
223225 if ( srcset ) {
224226 imageLink . setAttribute ( 'imagesrcset' , srcset ) ;
225- imageLink . setAttribute ( 'imagesizes' , '100vw' ) ;
227+ imageLink . setAttribute ( 'imagesizes' , state . enlargedSizes ) ;
226228 }
227229
230+ // Append the link element to the document head to trigger preloading.
228231 document . head . appendChild ( imageLink ) ;
229232 state . preloadedImageIds . add ( imageId ) ;
233+
234+ // Reset state after preloading the image.
235+ state . currentImageId = null ;
230236 } ,
231237 preloadImageWithDelay ( ) {
232238 const { imageId } = getContext ( ) ;
0 commit comments