Skip to content

Commit fa7404d

Browse files
fix(core): data-sizes="auto" on <source> tag (closes #9)
1 parent 626801a commit fa7404d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

packages/core/src/lazyLoad.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export function lazyLoad<T extends HTMLImageElement>(
2727
// Calculate the image's `sizes` attribute if `data-sizes="auto"` is set
2828
updateSizesAttribute(image)
2929

30+
// Update `sizes` attribute for source elements inside a picture element
31+
if (image.parentElement?.tagName.toLowerCase() === 'picture')
32+
[...image.parentElement.getElementsByTagName('source')].forEach(updateSizesAttribute)
33+
3034
// Generate the blurry placeholder from a Blurhash or ThumbHash string if applicable
3135
if (__ENABLE_HASH_DECODING__ && hash) {
3236
const placeholder = createPlaceholderFromHash({

0 commit comments

Comments
 (0)