-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
auto-sizes concrete object size ignoring natural dimensions is not implementable #9448
Comments
There are cases even with the spec as-is where you could create a cyclic dependency. A path forward might be to add size containment for images with this behaviour. [1] E.g. https://www.software.hixie.ch/utilities/js/live-dom-viewer/?saved=11811 We select an image based off this with a natural-size of say 400px, and wash-rinse-repeat. Ian |
So require |
Requiring strict dimensions ( |
Percentage widths as in @bfgeek's example is still problematic. Do you mean disallow percentages with "strict dimensions"? |
As for |
When reading up on containment, I found (this link) which says size containment was used to solve a similar cycle issue for container queries, so there is some precedent with this approach. Is it possible to make auto sizes imply size containment so it doesn't need to be specified? An alternative is to modify source selection to only go up in srcset options. The spec states that source selection is implementation-defined (selecting an image source), and Chromium currently implements this only-go-up behavior as an optimization to use larger images if they are available in the cache. This would not work for art direction, but that is probably best solved with other APIs (w3c/csswg-drafts#5889 has some info). |
The timing for parsing Size containment for images makes the height collapse to 0 if you only specify a width. It seems nice if we can avoid size containment as a requirement.
I think that still doesn't solve this, since the selection can go up to the largest image as noted in OP. Maybe you need |
One additional thing is that it's possible to create these cyclic dependencies with "auto" width/heights as well. E.g. https://www.software.hixie.ch/utilities/js/live-dom-viewer/?saved=11816 (the final width of the images are dependent on each others height). |
We have inline-size containment, which doesn't. I guess for this we would need width containment, which would be a different, new thing. |
Basically we need to ensure that image layout size doesn't rely on intrinsic width. We can check if intrinsic width will have any effect beforehand, and if so sub Checking & falling back to 100vw feels harder, spec-wise. It feels like there are many edge cases (?). I like that it wouldn't break existing layouts that are relying on intrinsic widths, but don't like that when sizes=auto isn't doing what people think it's doing, the problem will often be invisible. Shrinking intrinsically-sized images to 0-width is more noticeable, for better or for worse. |
Detecting if we've used an intrinsic size in layout gets into known hard layout problems very quickly. I suspect containment will be the best path forward. An option (perhaps not a good one) is to add a UA-style similar to |
Could the concrete object size be adjusted so the natural dimensions don't change as the result of auto sizes selection? For example, if natural dimensions are available when selecting the auto sizes source, adjust the selected image's natural dimensions to match. For cases where layout depends on intrinsic sizes, this would only perform two cycles. For the original issue of selecting all srcset options:
This approach would select "3x3.png 2w", resulting in a layout size of 3x3, then select "5x5.png 4w", which would still result in a layout size of 3x3 because the natural dimensions of 5x5.png would be adjusted to 3x3. For the width: 200%, fit-content parent issue:
This approach would select "2x2.png 2w", resulting in a layout size of 4x4, then select "4x4.png 4w", which would still result in a layout size of 4x4 because the natural dimensions of 4x4.png would be adjusted to 2x2. |
I wrote
This would be easy to write in the spec but maybe less easy to implement, since specified style isn't generally available per @emilio. Is this feasible in Chromium and WebKit?
Good point, we could allow
OK.
This doesn't work because @progers two requests per image which hasn't been acceptable in the past. |
Don't we still have the cycle issues with size containment approaches that don't constrain all axes? |
I think so, yeah... If we require explicit |
@zcorpan checking if there's a width or height specified is not enough, you need to make sure that the width is absolute right? |
|
Keep in mind the |
Do you have an example where intrinsic height affects the concrete width of an If so... I wonder how container queries get around this (or how the problems are different). |
Container queries don't persist "state" outside of layout (unless done by some web-developer script). The primary difference here (similar to content-visibility) is that "state" (what image you've selected). Put another way if you tear everything down, and run style+layout you'll end up with the same result each time. |
@bfgeek that makes a high-level kind of sense. The takeaway is, authors generally wouldn't be able use auto-sizes on content they don't know the intrinsic aspect ratio of. That will severely limit use (69% of |
A nice aspect of requiring size containment is that it's conservative and could be relaxed in the future based on developer feedback.
With auto sized natural dimensions, the typical behavior would just load one image. In cases where layout depends on the initial request, a second request is needed but it's progressive enhancement. The spec change for this would be to replace "concrete object size ignoring natural dimensions" with "auto sized natural dimensions" which is determined after some image in the srcset loads. Having a stateful srcset does seem strange though. |
This seems feasible, at least if the
I'm also curious about this! (Should be
I think performance-savvy developers at least will consider it a bug and will have to either not use auto-sizes or be mindful about how they use CSS to avoid double image requests. IMO it's not acceptable. |
Scrollbars are another example:
|
Thanks! Based on the comments so far, I suggest we do this:
This means it's not possible to use |
I am worried that size containment may not work for the common usecase where the image's height depends on the image. Is there data I could gather to determine if this is a requirement? For example, would it be useful to categorize usecases using lazysizes in httparchive data? I looked at example pages using srcset's w descriptor (link) and a lot of these could not be implemented with size containment. https://arabic.cnn.com is one of the first examples and the srcset images shrink in height as the browser window is dynamically sized smaller. I also looked into lazysizes.js and found it has double-downloading behavior for the scrollbar example above, and seems to prevent infinite loops by not aggressively tracking layout changes. |
@progers Shrinking in height as the browser window is dynamically resized is not a problem, as long as both dimensions are extrinsic. In this case, they are. We have one dimension ( I've been thinking about the clearest way to teach this proposal and "if you're using auto-sizes, use width and height attributes on img" seems very clear. I think that covers almost all cases (even the extremely common one where I do however worry that there are many contexts in which HTML is being authored by a person or system that doesn't know that aspect ratio. Templates, user-generated content... I'll spend some time tomorrow querying the HTTP Archive to see how many images that use srcset and w descriptors rely on intrinsic height. |
One thing that could be considered is setting the |
Fixing #3981 might help here, in that images with a different width than what was declared in |
So I did some querying, and tied myself into quite a few knots. As discussed, determining whether a given Here are my takeaways:
(also I hope @zcorpan’s right about #3981 and all of this is moot!) |
Checking the cases in this thread assuming we fix #3981:
|
In my mind, we would set the natural width of the element to whatever the For the height, I thought we could maybe honor the image's aspect ratio. If it's still an issue (e.g. for grid layout) to use the image's height or aspect ratio, we can require width/height attributes, but then we're back to similar behavior as size containment and developers need to know the aspect ratio beforehand. Also width/height attributes is not a guarantee that height does not change, since CSS can set width/height/aspect-ratio to something else. It's a bit hard to reason about this without being able to test. 🙂 |
Trying to wrap my head around what's acceptable/not acceptable here. In the scrollbar example with the "sizes sets the intrinsic width" proposal, we are running srcset selection twice, but I guess it's not a problem because (as long as we only load larger resources):
Those two are related... but I guess my question is, what exactly are we trying to prevent? Loading multiple resources AND running srcset selection an unbounded number of times both seem like blockers to me, but I want to confirm that understanding (and confirm that running srcset selection twice and possibly triggering one re-layout after load, is acceptable). |
If the scrollbar example is ok in this proposal, I guess the question becomes, can intrinsic height increasing ever make an |
IMO the requirements are:
Nice to have:
It seems we can't get all of the nice to haves. If we remove "unknown aspect ratio" and say that authors need to specify correct aspect ratio with Given @eeeps research in httparchive, the vast majority of images already have a specified aspect ratio, so easy adoption should be possible in those cases, even if we use size containment. To avoid duplicate loads and avoid magic, I think using size containment is best. In which case, #3981 is not a blocker, and we can do #9448 (comment) |
How does that work? Does I think we should probably enforce that |
Another research note: I was worried that even though ~80% of |
The latter. Should we have a note in the spec?
Hmm interesting, yeah that would be an alternative and then we don't need to check computed value. Is it helpful to have stricter syntax constraints around
edit: should be |
@eeeps thank you! |
Remember that <picture>
<source srcset="..." sizes=2400px>
<img sizes=auto loading=lazy>
</picture> |
@johannesodland indeed! Good call. Ideally the applied style rules don't change from initial layout. Resource selection for lazy images happens later, so having that affect UA style isn't good. We can require |
The 'concrete object size ignoring natural dimensions' concept was not implementable. This change makes `sizes=auto` required on `img` to use auto-sizes (still optional on `source`) and forces size containment so that the image size is the same before and after an image has loaded, to prevent double downloads. Fixes #9448.
PR: #9493 |
My own feelings and a tiny, informal poll lead me to believe that disappearing images without One thing we might be able to do to help here is add a |
@eeeps thanks, yeah agreed it's a bit surprising. Adding |
The 'concrete object size ignoring natural dimensions' concept was not implementable. This change makes `sizes=auto` required on `img` to use auto-sizes (still optional on `source`) and forces size containment so that the image size is the same before and after an image has loaded, to prevent double downloads. Fixes #9448.
The 'concrete object size ignoring natural dimensions' concept was not implementable. This change makes `sizes=auto` required on `img` to use auto-sizes (still optional on `source`) and forces size containment so that the image size is the same before and after an image has loaded, to prevent double downloads. Fixes #9448, fixes #9648, and fixes #9649.
… FixIt version (resolve #411) refer to whatwg/html#9448
Feedback from @progers in https://chromium-review.googlesource.com/c/chromium/src/+/4520266/comment/d6012d27_30cf4ea2/ about concrete object size ignoring natural dimensions introduced in #8008
The goal of the spec was to get stable, predictable, non-racy loading behavior of auto-sizes images. Therefore the natural dimensions of the loaded image shouldn't cause a different image to be selected from
srcset
.Consider a page like this:
The layout width before loading anything is 1px, so maybe the browser would select
a
. When that has loaded, the layout width changes to 2px, which could cause the browser to instead selectb
. And so on until the largest image has loaded.The spec checks for 0px concrete object size ignoring natural dimensions and translates
auto
to100vw
. But sincemin-width
can be used, the image's natural dimensions can still affect the layout size as shown above.@emilio pointed out that the natural dimensions can affect outer elements, so it's not easy to determine the concrete object size ignoring natural dimensions without doing full layout twice.
So I think we need a different approach here. Maybe checking if there's a specified 'width' (or 'height' + 'aspect-ratio'), and if not use
100vw
. Any other ideas?cc @tcaptan-cr @yoavweiss
The text was updated successfully, but these errors were encountered: