Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML: test <img sizes=auto> #34427

Merged
merged 11 commits into from
Jun 2, 2023
Merged

HTML: test <img sizes=auto> #34427

merged 11 commits into from
Jun 2, 2023

Conversation

zcorpan
Copy link
Member

@zcorpan zcorpan commented Jun 14, 2022

@zcorpan
Copy link
Member Author

zcorpan commented Jul 6, 2022

Not tested yet:

  • "concrete object size ignoring natural dimensions" width change is a relevant mutation
  • loading attribute state change is a relevant mutation
  • "being rendered" change is a relevant mutation
  • no specified dimensions (maps to 100vw)
  • 'left' and 'right' with absolute or fixed positioning (like no specified dimensions)
  • dimensions specified using
    • 'height'/'min-height' and 'aspect-ratio'
    • 'inline-size'/'min-inline-size'/'block-size'/'min-block-size' with 'writing-mode' and 'aspect-ratio'
    • percentage
    • var()
    • math functions

@zcorpan
Copy link
Member Author

zcorpan commented Jul 8, 2022

I'll be off work between now and August 8. I can continue working on this then.

@yoavweiss
Copy link
Contributor

I'll be off work between now and August 8. I can continue working on this then.

Enjoy! Feel free to ping me once you need me to review changes, etc

@zcorpan
Copy link
Member Author

zcorpan commented Aug 11, 2022

OK everything I was planning to test is now done. @yoavweiss PTAL


t('width attribute changes', function(img) {
img.width = '4';
}, 'load');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So update the image data re-fires the load event, even if the image hasn't changed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I'm not a huge fan, but it's what browsers do.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just did a test using only srcset with several options and the same url, and when I resized the browser window, I don't see the on-load event fire. Is this test expectation for auto-sizes correct? I would expect the on-load event to fire if a different image was selected, as it does for srcset.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Browsers fire a 'load' event for relevant mutations, see https://software.hixie.ch/utilities/js/live-dom-viewer/saved/11615

Since the spec makes layout size changes a relevant mutation, the implication is that layout changes for the image are expected to fire load even if currentSrc didn't change. See whatwg/html#8492 about changing this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed pass conditions per whatwg/html#8008 (comment)

Copy link
Contributor

@yoavweiss yoavweiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests LGTM assuming we can land this spec change from a compat perspective.

chromium-wpt-export-bot pushed a commit that referenced this pull request May 12, 2023
Spec PR:
whatwg/html#8008

WPT tests PR:
#34427

R=pdr

Bug: 1359051
Change-Id: I8e9bc836e9582a9209db53d55e0edc96f90499f2
chromium-wpt-export-bot pushed a commit that referenced this pull request May 18, 2023
Spec PR:
whatwg/html#8008

WPT tests PR:
#34427

R=pdr

Bug: 1359051
Change-Id: I8e9bc836e9582a9209db53d55e0edc96f90499f2
chromium-wpt-export-bot pushed a commit that referenced this pull request May 18, 2023
Spec PR:
whatwg/html#8008

WPT tests PR:
#34427

R=pdr

Bug: 1359051
Change-Id: I8e9bc836e9582a9209db53d55e0edc96f90499f2
chromium-wpt-export-bot pushed a commit that referenced this pull request May 19, 2023
Spec PR:
whatwg/html#8008

WPT tests PR:
#34427

R=pdr

Bug: 1359051
Change-Id: I8e9bc836e9582a9209db53d55e0edc96f90499f2
chromium-wpt-export-bot pushed a commit that referenced this pull request May 20, 2023
Spec PR:
whatwg/html#8008

WPT tests PR:
#34427

R=pdr

Bug: 1359051
Change-Id: I8e9bc836e9582a9209db53d55e0edc96f90499f2
chromium-wpt-export-bot pushed a commit that referenced this pull request May 20, 2023
Spec PR:
whatwg/html#8008

WPT tests PR:
#34427

R=pdr

Bug: 1359051
Change-Id: I8e9bc836e9582a9209db53d55e0edc96f90499f2
@zcorpan zcorpan requested a review from tcaptan-cr May 31, 2023 17:05
// lazy-loaded images should have fired their first 'load' event at this point.

t('width attribute changes', function(img) {
img.width = '4';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this test also expect timeout, like the test bellow which changes img.style.width?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The width attribute is listed as a relevant mutation: https://html.spec.whatwg.org/#relevant-mutations

However, it might be a leftover that should have been removed in whatwg/html#5900 . I can file an issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!


t('loading attribute state changes', function(img) {
img.loading = 'eager';
}, 'load');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the image is already loaded, why would changing the loading attribute trigger a load event?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

State changes to the loading attribute is a relevant mutation per https://github.com/whatwg/html/pull/8008/files#diff-41cf6794ba4200b839c53531555f0f3998df4cbb01a4d5cb0b94e3ca5e23947dR30115-R30116

The "auto" keyword is calculated differently depending on the state of loading. But I'm now uncertain if it should be a relevant mutation. https://html.spec.whatwg.org/#the-img-element:lazy-loading-attribute already handles the state changing to Eager, so also making it a relevant mutation is questionable...

@yoavweiss @domfarolino any opinions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it seems that that specific algorithm replaces the relevant mutation logic (and is more specific). So I'm favorable of removing it from the relevant mutations.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Thinking about it again, it's invalid to use auto for eager images, so if you want to switch to eager you should also change sizes (which is a relevant mutation). OK I'll fix the spec and tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would happen if authors don't change sizes in that case? Would that modify the image's intrinsic dimensions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, auto would compute to 100vw, but not until another relevant mutation happens I think.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that runs a risk of being confusing.
I wonder if there's room to define auto + eager as taking the known dimensions in case they are indeed known (and only fallback to 100vw when they aren't)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whatwg/html#8008 (comment)

I prefer the invalid mutation case being somewhat confusing to introducing non-deterministic loading of eager images.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair! (and apologies for rehashing a past discussion :D)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np :)

Copy link
Contributor

@tcaptan-cr tcaptan-cr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall the change looks good to me. I only have 2 questions on relevant-mutations-lazy.html.

@zcorpan zcorpan force-pushed the bocoup/img-sizes-auto branch from 1c7b50e to a442c1c Compare June 2, 2023 13:40
@zcorpan zcorpan merged commit 1d96e07 into master Jun 2, 2023
@zcorpan zcorpan deleted the bocoup/img-sizes-auto branch June 2, 2023 14:23
chromium-wpt-export-bot pushed a commit that referenced this pull request Jun 4, 2023
Auto Sizes allows developers to omit the sizes attribute (or set it to
sizes=auto) for lazy loaded image elements with srcset. For this use
case the image's width should be provided. The browser will use the
layout width of the image in order to select the source url from the
srcset.

Spec PR:
whatwg/html#8008

WPT tests PR:
#34427

Chrome Platform Status link:
https://chromestatus.com/feature/5191555708616704

Intent to Prototype link:
https://groups.google.com/a/chromium.org/g/blink-dev/c/AYoqvNluyeA

R=pdr

Bug: 1359051
Change-Id: I8e9bc836e9582a9209db53d55e0edc96f90499f2
chromium-wpt-export-bot pushed a commit that referenced this pull request Jun 5, 2023
Auto Sizes allows developers to omit the sizes attribute (or set it to
sizes=auto) for lazy loaded image elements with srcset. For this use
case the image's width should be provided. The browser will use the
layout width of the image in order to select the source url from the
srcset.

Spec PR:
whatwg/html#8008

WPT tests PR:
#34427

Chrome Platform Status link:
https://chromestatus.com/feature/5191555708616704

Intent to Prototype link:
https://groups.google.com/a/chromium.org/g/blink-dev/c/AYoqvNluyeA

R=pdr

Bug: 1359051
Change-Id: I8e9bc836e9582a9209db53d55e0edc96f90499f2
chromium-wpt-export-bot pushed a commit that referenced this pull request Jun 5, 2023
Auto Sizes allows developers to omit the sizes attribute (or set it to
sizes=auto) for lazy loaded image elements with srcset. For this use
case the image's width should be provided. The browser will use the
layout width of the image in order to select the source url from the
srcset.

Spec PR:
whatwg/html#8008

WPT tests PR:
#34427

Chrome Platform Status link:
https://chromestatus.com/feature/5191555708616704

Intent to Prototype link:
https://groups.google.com/a/chromium.org/g/blink-dev/c/AYoqvNluyeA

R=pdr

Bug: 1359051
Change-Id: I8e9bc836e9582a9209db53d55e0edc96f90499f2
chromium-wpt-export-bot pushed a commit that referenced this pull request Jun 6, 2023
Auto Sizes allows developers to omit the sizes attribute (or set it to
sizes=auto) for lazy loaded image elements with srcset. For this use
case the image's width should be provided. The browser will use the
layout width of the image in order to select the source url from the
srcset.

Spec PR:
whatwg/html#8008

WPT tests PR:
#34427

Chrome Platform Status link:
https://chromestatus.com/feature/5191555708616704

Intent to Prototype link:
https://groups.google.com/a/chromium.org/g/blink-dev/c/AYoqvNluyeA

R=pdr

Bug: 1359051
Change-Id: I8e9bc836e9582a9209db53d55e0edc96f90499f2
chromium-wpt-export-bot pushed a commit that referenced this pull request Jun 6, 2023
Auto Sizes allows developers to omit the sizes attribute (or set it to
sizes=auto) for lazy loaded image elements with srcset. For this use
case the image's width should be provided. The browser will use the
layout width of the image in order to select the source url from the
srcset.

Spec PR:
whatwg/html#8008

WPT tests PR:
#34427

Chrome Platform Status link:
https://chromestatus.com/feature/5191555708616704

Intent to Prototype link:
https://groups.google.com/a/chromium.org/g/blink-dev/c/AYoqvNluyeA

R=pdr

Bug: 1359051
Low-Coverage-Reason: For html_srcset_parser.cc, it should be
                     covered by `image-srcset-cache.html`
                     but there seems to be cov reporing problem.
Change-Id: I8e9bc836e9582a9209db53d55e0edc96f90499f2
chromium-wpt-export-bot pushed a commit that referenced this pull request Jun 6, 2023
Auto Sizes allows developers to omit the sizes attribute (or set it to
sizes=auto) for lazy loaded image elements with srcset. For this use
case the image's width should be provided. The browser will use the
layout width of the image in order to select the source url from the
srcset.

Spec PR:
whatwg/html#8008

WPT tests PR:
#34427

Chrome Platform Status link:
https://chromestatus.com/feature/5191555708616704

Intent to Prototype link:
https://groups.google.com/a/chromium.org/g/blink-dev/c/AYoqvNluyeA

R=pdr

Bug: 1359051
Low-Coverage-Reason: For html_srcset_parser.cc, it should be
                     covered by `image-srcset-cache.html`
                     but there seems to be cov reporing problem.
Change-Id: I8e9bc836e9582a9209db53d55e0edc96f90499f2
chromium-wpt-export-bot pushed a commit that referenced this pull request Jun 7, 2023
Auto Sizes allows developers to omit the sizes attribute (or set it to
sizes=auto) for lazy loaded image elements with srcset. For this use
case the image's width should be provided. The browser will use the
layout width of the image in order to select the source url from the
srcset.

Spec PR:
whatwg/html#8008

WPT tests PR:
#34427

Chrome Platform Status link:
https://chromestatus.com/feature/5191555708616704

Intent to Prototype link:
https://groups.google.com/a/chromium.org/g/blink-dev/c/AYoqvNluyeA

R=pdr

Bug: 1359051
Low-Coverage-Reason: For html_srcset_parser.cc, it should be
                     covered by `image-srcset-cache.html`
                     but there seems to be cov reporing problem.
Change-Id: I8e9bc836e9582a9209db53d55e0edc96f90499f2
chromium-wpt-export-bot pushed a commit that referenced this pull request Jun 8, 2023
Auto Sizes allows developers to omit the sizes attribute (or set it to
sizes=auto) for lazy loaded image elements with srcset. For this use
case the image's width should be provided. The browser will use the
layout width of the image in order to select the source url from the
srcset.

Spec PR:
whatwg/html#8008

WPT tests PR:
#34427

Chrome Platform Status link:
https://chromestatus.com/feature/5191555708616704

Intent to Prototype link:
https://groups.google.com/a/chromium.org/g/blink-dev/c/AYoqvNluyeA

R=pdr

Bug: 1359051
Low-Coverage-Reason: For html_srcset_parser.cc, it should be
                     covered by `image-srcset-cache.html`
                     but there seems to be cov reporing problem.
Change-Id: I8e9bc836e9582a9209db53d55e0edc96f90499f2
chromium-wpt-export-bot pushed a commit that referenced this pull request Jun 14, 2023
Auto Sizes allows developers to omit the sizes attribute (or set it to
sizes=auto) for lazy loaded image elements with srcset. For this use
case the image's width should be provided. The browser will use the
layout width of the image in order to select the source url from the
srcset.

Spec PR:
whatwg/html#8008

WPT tests PR:
#34427

Chrome Platform Status link:
https://chromestatus.com/feature/5191555708616704

Intent to Prototype link:
https://groups.google.com/a/chromium.org/g/blink-dev/c/AYoqvNluyeA

R=pdr

Bug: 1359051
Low-Coverage-Reason: For html_srcset_parser.cc, it should be
                     covered by `image-srcset-cache.html`
                     but there seems to be cov reporing problem.
Change-Id: I8e9bc836e9582a9209db53d55e0edc96f90499f2
chromium-wpt-export-bot pushed a commit that referenced this pull request Jun 15, 2023
Auto Sizes allows developers to omit the sizes attribute (or set it to
sizes=auto) for lazy loaded image elements with srcset. For this use
case the image's width should be provided. The browser will use the
layout width of the image in order to select the source url from the
srcset.

Spec PR:
whatwg/html#8008

WPT tests PR:
#34427

Chrome Platform Status link:
https://chromestatus.com/feature/5191555708616704

Intent to Prototype link:
https://groups.google.com/a/chromium.org/g/blink-dev/c/AYoqvNluyeA

R=pdr

Bug: 1359051
Low-Coverage-Reason: For html_srcset_parser.cc, it should be
                     covered by `image-srcset-cache.html`
                     but there seems to be cov reporing problem.
Change-Id: I8e9bc836e9582a9209db53d55e0edc96f90499f2
chromium-wpt-export-bot pushed a commit that referenced this pull request Jun 15, 2023
Auto Sizes allows developers to omit the sizes attribute (or set it to
sizes=auto) for lazy loaded image elements with srcset. For this use
case the image's width should be provided. The browser will use the
layout width of the image in order to select the source url from the
srcset.

Spec PR:
whatwg/html#8008

WPT tests PR:
#34427

Chrome Platform Status link:
https://chromestatus.com/feature/5191555708616704

Intent to Prototype link:
https://groups.google.com/a/chromium.org/g/blink-dev/c/AYoqvNluyeA

R=pdr

Bug: 1359051
Low-Coverage-Reason: For html_srcset_parser.cc, it should be
                     covered by `image-srcset-cache.html`
                     but there seems to be cov reporing problem.
Change-Id: I8e9bc836e9582a9209db53d55e0edc96f90499f2
chromium-wpt-export-bot pushed a commit that referenced this pull request Jun 15, 2023
Auto Sizes allows developers to omit the sizes attribute (or set it to
sizes=auto) for lazy loaded image elements with srcset. For this use
case the image's width should be provided. The browser will use the
layout width of the image in order to select the source url from the
srcset.

Spec PR:
whatwg/html#8008

WPT tests PR:
#34427

Chrome Platform Status link:
https://chromestatus.com/feature/5191555708616704

Intent to Prototype link:
https://groups.google.com/a/chromium.org/g/blink-dev/c/AYoqvNluyeA

R=pdr

Bug: 1359051
Low-Coverage-Reason: For html_srcset_parser.cc, it should be
                     covered by `image-srcset-cache.html`
                     but there seems to be cov reporing problem.
Change-Id: I8e9bc836e9582a9209db53d55e0edc96f90499f2
chromium-wpt-export-bot pushed a commit that referenced this pull request Jun 15, 2023
Auto Sizes allows developers to omit the sizes attribute (or set it to
sizes=auto) for lazy loaded image elements with srcset. For this use
case the image's width should be provided. The browser will use the
layout width of the image in order to select the source url from the
srcset.

Spec PR:
whatwg/html#8008

WPT tests PR:
#34427

Chrome Platform Status link:
https://chromestatus.com/feature/5191555708616704

Intent to Prototype link:
https://groups.google.com/a/chromium.org/g/blink-dev/c/AYoqvNluyeA

R=pdr

Bug: 1359051
Low-Coverage-Reason: For html_srcset_parser.cc, it should be
                     covered by `image-srcset-cache.html`
                     but there seems to be cov reporing problem.
Change-Id: I8e9bc836e9582a9209db53d55e0edc96f90499f2
chromium-wpt-export-bot pushed a commit that referenced this pull request Jun 15, 2023
Auto Sizes allows developers to omit the sizes attribute (or set it to
sizes=auto) for lazy loaded image elements with srcset. For this use
case the image's width should be provided. The browser will use the
layout width of the image in order to select the source url from the
srcset.

Spec PR:
whatwg/html#8008

WPT tests PR:
#34427

Chrome Platform Status link:
https://chromestatus.com/feature/5191555708616704

Intent to Prototype link:
https://groups.google.com/a/chromium.org/g/blink-dev/c/AYoqvNluyeA

R=pdr

Bug: 1359051
Low-Coverage-Reason: For html_srcset_parser.cc, it should be
                     covered by `image-srcset-cache.html`
                     but there seems to be cov reporing problem.
Change-Id: I8e9bc836e9582a9209db53d55e0edc96f90499f2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants