Skip to content

Commit

Permalink
bug fixes: fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
arturmagalhaesjr committed Dec 6, 2024
1 parent 91f908f commit 868d6b6
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions react/components/LazyImages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,21 @@ const MaybeLazyImage: FC<MaybeLazyImageProps> = ({
/** adds `lazyload` class to enable lazysizes, and moves the image URI
* from src to data-src. `styles.lazyload` is used to hide the "broken image"
* symbol while the image hasn't been loaded */
newImageProps = {
...imageProps,
// explicity key because we need react to re-render the whole img element
// in case the src changes (i.e: product-summary + sku)
key: imageProps.src,
className: `lazyload ${imageProps.className ?? ''} ${
styles.lazyload
}`,
src: undefined,
'data-src': imageProps.src,
loading: newImageProps.loading ?? 'lazy',
if (newImageProps.loading !== 'eager') {
newImageProps = {
...imageProps,
// explicity key because we need react to re-render the whole img element
// in case the src changes (i.e: product-summary + sku)
key: imageProps.src,
className: `lazyload ${imageProps.className ?? ''} ${
styles.lazyload
}`,
src: undefined,
'data-src': imageProps.src,
loading: 'lazy',
}
}

break
}
return createElement.apply(React, ['img', newImageProps])
Expand Down

0 comments on commit 868d6b6

Please sign in to comment.