-
Notifications
You must be signed in to change notification settings - Fork 708
[css-flexbox] Change content-size suggestion to min-intrinsic instead of min-content? #6794
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
Comments
… element. If the flex item is a non-replaced element and its min-width/min-height is 'auto', the spec has changed so that it has no transferred size suggestion now. https://drafts.csswg.org/css-flexbox-1/#min-size-auto This patch also updates WPT tests to fix #27878 Differential Revision: https://phabricator.services.mozilla.com/D112830 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1703304 gecko-commit: fb14e6d29a44a79efc296cc727f92aa58ea4dacc gecko-reviewers: dholbert
Looks like Gecko does something like
or maybe Gecko floors the entire automatic minimum size?
Seems reasonable and Blink can try to match if that's the behavior we end up adopting. @dholbert @aethanyc , can you report what logic Gecko follows such that the flex item in https://jsfiddle.net/dgrogan/2734sdfr/ has automatic minimum width of 100px? |
For the flex item in https://jsfiddle.net/dgrogan/2734sdfr/, Firefox only has content size suggestion, which follows the same logic described in https://drafts.csswg.org/css-sizing-4/#aspect-ratio-minimum, i.e.
Firefox currently only applies specified size suggestion only if there's a main size property. However, the current spec implies that the specified size suggestion is the item’s preferred main size, which can be computed via aspect-ratio + definite cross-size. @dholbert pointed to me that the definition was changed after the edit in 0c1a35d, and this seems changing the behavior. |
Oh, y'all apply aspect-ratio's automatic minimum size on top of flex's. Maybe Blink should match. Blink matches Gecko about when to apply specified side suggestion. |
https://drafts.csswg.org/css-flexbox-1/#min-size-auto gives one definition of automatic minimum sizing. https://drafts.csswg.org/css-sizing-4/#aspect-ratio-minimum gives another. They don't always agree. @tabatkins @fantasai , what do we do in the case of a flex item with an aspect ratio? Apply both minimums? Chrome only applies flexbox's. I think Firefox applies both. |
The underlying behavior difference may explain why firefox and chrome have different renderings for the example below. <div style="display: flex; flex-direction: column; height: 0px;">
<div style="aspect-ratio: 1/1; width: 100px; border: 5px solid orange;">
<div style="height: 200%; background: blue;"></div>
</div>
</div> Chrome 99 canary gives 0 height to both orange item and blue child. |
The CSS Working Group just discussed The full IRC log of that discussion<emeyer> Topic: [css-flexbox] Change content-size suggestion to min-intrinsic instead of min-content?<emeyer> github: https://github.com//issues/6794 <emeyer> fantasai: I think I need to go back to read the flexbox specs from the very beginning to figure out what I think should happen here. <emeyer> …I think we have to decide what behavior we want here and how to achieve that. <emeyer> …I’m not sure I’m clear on any of that. <emeyer> TabAtkins: Same here. This is important and VERY difficult to reason about correctly, and we need more time. <emeyer> dgrogan: Base issue is that aspect-ratio define sizing one way and flex defines it another <emeyer> …and they conflict when you aspect-ratio a flex item. <emeyer> TabAtkins: That’s what I understand. I don’t know how to resolve that yet. <emeyer> dgrogan: Before we start talking about changing the spec, should I change Chrome to match Firefox where they apply both minimums? <emeyer> TabAtkins: Wouldn’t that answer the question? <emeyer> …Because if you change to match Firefox, then the spec will just match whetever you do. <emeyer> dgrogan: Okay, let’s pinch this off now. <emeyer> astearns: Will remove Agenda+ and will put it back once fantasai and tabatkins have time. <emeyer> iank_: Can we do this quickly? It’s a major problem. <emeyer> TabAtkins: That’s the goal. <emeyer> astearns: Let’s wait on this for now. |
@tabatkins and I think some of the confusion here comes from missing a small nuance in this paragraph:
The flex item in question does not have a specified size suggestion, and is not replaced, and therefore it falls through to the final clause and uses its content size suggestion which is its min-content size in the main axis (100px). Therefore Firefox's behavior here is correct. @aethanyc mentioned
0c1a35d was definitely not meant to change behavior, but I can see how switching the emphasis from the “computed value” would change how automatic sizes are interpreted. We need to clarify that we're only considering non-automatic definite sizes: diff --git a/css-flexbox-1/Overview.bs b/css-flexbox-1/Overview.bs
index 2c3418beb..358740409 100644
--- a/css-flexbox-1/Overview.bs
+++ b/css-flexbox-1/Overview.bs
@@ -1001,7 +1001,7 @@ Grid doesn't have similarly meaningful shrinkability, so it doesn't need to care
<dl>
<dt><dfn>specified size suggestion</dfn>
<dd>
- If the item’s [=preferred size|preferred=] [=main size=] is <a>definite</a>,
+ If the item’s [=preferred size|preferred=] [=main size=] is <a>definite</a> and not [=automatic size|automatic=],
then the <a>specified size suggestion</a> is that size.
It is otherwise undefined. Committed in ca4dc9e . |
In #6794 (comment), <div style="display: flex; flex-direction: column; height: 0px;">
<div style="aspect-ratio: 1/1; width: 100px; border: 5px solid orange;">
<div style="height: 200%; background: blue;"></div>
</div>
</div> Chrome's behavior here is correct. The min-content contribution of the blue box is zero due to the cyclic percentage size rules in https://www.w3.org/TR/css-sizing-3/#cyclic-percentage-contribution. So the flex base size is 100px (from the transferred width), and the automatic minimum size is zero, resulting in a 100px hypothetical main size. Then, since the flex container is 0px tall and the item is flexible, it shrinks down to its minimum size (0px). The blue box's percentage then resolves against that zero during layout, so the blue box is also zero. Firefox renders this with a 200px tall orange box, and a 400px tall blue box, which means in their implementation the percentage is looping and self-applying, and just happens to be cut off on two applications. This is because they are not applying the cyclic percentage rules |
Propose to close as editorial / invalid. Please let us know if we need to consider anything else! |
Could you explicitly say which engine, if any, renders the original case correctly? <div style="display: flex;">
<!-- Chrome says final width is 50px. Firefox says 100px. -->
<div style="background: blue; height: 100px; aspect-ratio: 1/2; ">
<div style="width: 100px;"></div>
</div>
</div> |
Unless there's something we missed? |
@tabatkins , one thing I'm confused about in your analysis -- you say:
Why do you say the automatic minimum size is zero -- shouldn't it actually be 100px? The flex item here should use the content-size suggestion i.e. its min-content height, per https://drafts.csswg.org/css-flexbox-1/#min-size-auto (since it doesn't have a specified size suggestion and is not replaced). And I think its min-content height is 100px, not 0. At least, this simplified example (with just a single div that has explicit <!DOCTYPE html>
<div style="aspect-ratio: 1/1;
width: 100px; height: min-content;
background: blue; border: 5px solid orange">
</div> Browsers agree that this^ div is 100px tall, which I think (?) means its |
For completeness, I'll point out that browsers also agree that the div in the other example here (the row-oriented flex container that @davidsgrogan asked about) does indeed have a 100px min-content width which (as fantasai noted) agrees with Firefox's behavior in that case. Here's a simplified example with <div style="aspect-ratio: 1/2;
height: 100px; width: min-content;
background: blue; border: 5px solid orange">
<div style="width: 100px;"></div>
</div> In this^ case, the min-content width does actually come from its content, i.e. its 100px-wide child; but if you edit the example to remove that child, then browsers also agree that the div ends up being 50px wide there instead (from the aspect-ratio and cross-axis size). So, this seems to be further confirmation that the min-content size is indeed established by the aspect-ratio and the opposite-axis property (though it might be bigger the element contains content that is even larger). |
@dholbert - That example is using the
In the above case all browsers agree that its 50px. |
@bfgeek aha, thank you for clarifying that. I had forgotten that aspect-ratio had its own special
|
@dholbert - Given that clarification I think there is still a terminology issue here. E.g. <div style="display: flex;">
<!-- Chrome says final width is 50px. Firefox says 100px. -->
<div style="background: blue; height: 100px; aspect-ratio: 1/2; ">
<div style="width: 100px;"></div>
</div>
</div>
In the given example (afaikt) the min-content size (given that it has an aspect-ratio) is actually One thing that might mitigate the confusion here is to change the definition of Ian |
[retracting my "things make sense" comment] So per @bfgeek 's example and comments, it sounds like the min-content size of an element with So, my confusion from #6794 (comment) remains -- I'm not sure I agree with @tabatkins that the automatic minimum height of the flex item would be zero in Tab's analysis in #6794 (comment) . I would think it should be the min-content size, which (per bfgeek's notes about how |
Mea culpa, you're right. When writing that down, I tripped over the fact that (a) the blue child resolves to 0 height while calculating the automatic minimum size, and (b) the specified size suggestion shouldn't take aspect-ratio into account (we had just dropped a minor edit into there to make sure that automatic sizes couldn't contribute even if they're definite), and so forgot to think about aspect-ratio when talking about the content size suggestion, which should take that into account. You're correct that the automatic minimum size in this case is 100px. So neither Chrome nor Firefox is quite right here. Instead, the orange item starts at 100px flex basis, isn't allowed to shrink below 100px, and the blue child then resolves its % against that, resulting in the blue box being 200px tall. |
Sorry, I totally missed that paragraph. But the content size suggestion is not 100px, it's 50px (as mentioned in #6794 (comment)). My point from #6794 (comment) still stands. Slightly reworded: https://drafts.csswg.org/css-flexbox-1/#min-size-auto gives a definition of automatic minimum sizing for flex items. So what do we do in the case of a flex item with an aspect ratio? Which minimum do we apply? These definitions need to be modified so that they always agree (which I think is what Ian proposes in the last sentence of #6794 (comment)) OR if they don't agree, we need explicit instruction of which to honor (which is possibly both). |
Where are you getting that from? Are you assuming this is from the aspect-ratio affecting the specified size suggestion? We made a small tweak to prevent that, specifying it only looks at non-automatic definite sizes, specifically because it was creating an unintentional conflict with the aspect-ratio auto minimum size. (And was pre-empting the other size suggestions which were intended to handle aspect ratios.) (And it was just wrong anyway, as it would made made |
Yeah, we should make it clear what to do when they disagree. I suspect we want to honor the larger of the two (aka both minimums are active). |
I'm describing how engines derive the min-content size of a non-replaced element with an aspect-ratio - (which feeds into the content suggestion for this specific example). E.g. for this case this rectangle has a min-content size of 50px :
The min-content size itself doesn't apply any automatic minimum sizing. (We don't read min-width when computing the min-content size). One option here is that it can! This would solve the issue. Given that above is 50px we feed this into the content size suggestion which gives Chrome's output for the flexbox example being talked about. |
#5268 is the related question whether aspect-ratio's automatic minimum size should be applied in both axes or just in the block axis. |
New expectations incorporate an item's min-intrinsic size as part of flex's automatic minimum sizing. The new expectations are arguably what the spec currently calls for AND what the spec authors originally intended AND are consistent with both relevant proposals in w3c/csswg-drafts#6794 Also discussed at web-platform-tests/interop#139 (comment) Change-Id: I3c6ecdf66fbb4ee745c88b6b2a4dbecfb9913908
New expectations incorporate an item's min-intrinsic size as part of flex's automatic minimum sizing. The new expectations are arguably what the spec currently calls for AND what the spec authors originally intended AND are consistent with both relevant proposals in w3c/csswg-drafts#6794 Also discussed at web-platform-tests/interop#139 (comment) Change-Id: I3c6ecdf66fbb4ee745c88b6b2a4dbecfb9913908 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3924134 Commit-Queue: David Grogan <dgrogan@chromium.org> Reviewed-by: Ian Kilpatrick <ikilpatrick@chromium.org> Cr-Commit-Position: refs/heads/main@{#1052123}
New expectations incorporate an item's min-intrinsic size as part of flex's automatic minimum sizing. The new expectations are arguably what the spec currently calls for AND what the spec authors originally intended AND are consistent with both relevant proposals in w3c/csswg-drafts#6794 Also discussed at web-platform-tests/interop#139 (comment) Change-Id: I3c6ecdf66fbb4ee745c88b6b2a4dbecfb9913908 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3924134 Commit-Queue: David Grogan <dgrogan@chromium.org> Reviewed-by: Ian Kilpatrick <ikilpatrick@chromium.org> Cr-Commit-Position: refs/heads/main@{#1052123}
New expectations incorporate an item's min-intrinsic size as part of flex's automatic minimum sizing. The new expectations are arguably what the spec currently calls for AND what the spec authors originally intended AND are consistent with both relevant proposals in w3c/csswg-drafts#6794 Also discussed at web-platform-tests/interop#139 (comment) Change-Id: I3c6ecdf66fbb4ee745c88b6b2a4dbecfb9913908 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3924134 Commit-Queue: David Grogan <dgrogan@chromium.org> Reviewed-by: Ian Kilpatrick <ikilpatrick@chromium.org> Cr-Commit-Position: refs/heads/main@{#1052123}
…pect-ratio tests, a=testonly Automatic update from web-platform-tests [css-flex] Change expectations of two aspect-ratio tests New expectations incorporate an item's min-intrinsic size as part of flex's automatic minimum sizing. The new expectations are arguably what the spec currently calls for AND what the spec authors originally intended AND are consistent with both relevant proposals in w3c/csswg-drafts#6794 Also discussed at web-platform-tests/interop#139 (comment) Change-Id: I3c6ecdf66fbb4ee745c88b6b2a4dbecfb9913908 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3924134 Commit-Queue: David Grogan <dgrogan@chromium.org> Reviewed-by: Ian Kilpatrick <ikilpatrick@chromium.org> Cr-Commit-Position: refs/heads/main@{#1052123} -- wpt-commits: 8160da618bad50684232b7865e956827efe18072 wpt-pr: 36113
…pect-ratio tests, a=testonly Automatic update from web-platform-tests [css-flex] Change expectations of two aspect-ratio tests New expectations incorporate an item's min-intrinsic size as part of flex's automatic minimum sizing. The new expectations are arguably what the spec currently calls for AND what the spec authors originally intended AND are consistent with both relevant proposals in w3c/csswg-drafts#6794 Also discussed at web-platform-tests/interop#139 (comment) Change-Id: I3c6ecdf66fbb4ee745c88b6b2a4dbecfb9913908 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3924134 Commit-Queue: David Grogan <dgrogan@chromium.org> Reviewed-by: Ian Kilpatrick <ikilpatrick@chromium.org> Cr-Commit-Position: refs/heads/main@{#1052123} -- wpt-commits: 8160da618bad50684232b7865e956827efe18072 wpt-pr: 36113
…lex items. https://bugs.webkit.org/show_bug.cgi?id=246755 rdar://101346126 Reviewed by Rob Buis. There has been a lot of conversation on computing the min-content size for flex items when computing the content size suggestion. In particular, there were potential issues when computing the min-content size for non-replaced flex items that were given an aspect-ratio property. This issue was brought up in the following CSSWG conversation: w3c/csswg-drafts#6794 When the conversation was initially created, browsers all had different behaviors. A patch was added to make WebKit behavior similar to the behavior of Blink: WebKit#3025 The patch added behavior to take the aspect ratio into consideration when computing these sizes. This behavior ended up being incorrect by the time consensus was reached. The final decision seems to be that we should be computing the min-intrinsic size, which does not take into consideration the aspect-ratio and is just based off of the content. The idea of the min-intrinsic size was introduced here: w3c/csswg-drafts#5305 Since our initial behavior was close to the behavior that was eventually agreed upon, this patch ends up being mostly a revert. It is not completely a revert, however, since there are still some pieces left in from the initial patch. If the item is a replaced element, we will start take into consideration the aspect-ratio and compute the size using computeMainSizeFromAspectRatioUsing. If the item is a non-replaced element, instead we will compute the size using computeMainAxisExtentForChild. This will compute the min-intrinsic size by calling either child.computeLogicalWidthInFragmentUsing or child.computeContentLogicalHeight. Spec reference: https://drafts.csswg.org/css-flexbox-1/#min-size-auto Follow up discussion: web-platform-tests/interop#139 * LayoutTests/TestExpectations: * LayoutTests/imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/flex-aspect-ratio-002.html: * LayoutTests/imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/flex-aspect-ratio-004.html: Newest version of the tests * Source/WebCore/rendering/RenderFlexibleBox.cpp: (WebCore::RenderFlexibleBox::computeFlexItemMinMaxSizes): Canonical link: https://commits.webkit.org/255858@main
@mirisuzanne Were you able to compile any thoughts here? |
I'm not sure I have anything new to provide here. I'm not a big fan of the default flex values, but that ship has long sailed. I'm also not fully-versed in all the intricacies and magics involved with the different sizing algorithms discussed - which makes it hard to comment on the difference between At the higher level of my author expectations:
When using aspect-ratio with flexbox, I would almost never set an explicit size on the cross-axis. The whole point would be maintaining a ratio as the item flexes. The only reason I can imagine ending up in this situation is if I'm using flexbox to lay out non-flexible items. Either way, I would want to clarify:
Of course we need a default here, but I don't see a 'right' one. Both defaults look broken, because this is not a clear use-case - and I would want to provide a fix either way. Like I said in the call: what's important to me is that I have good options for clarifying my intent in either direction once this breaks. It would be a lot easier to comment here if any of the examples were based in actual use-cases. |
As a data-point, we a starting to receive some bug reports about out behaviour (specifically for this case: https://www.software.hixie.ch/utilities/js/live-dom-viewer/?saved=12476 [1] ) With people expecting WebKit's behaviour. [1]
(in the row direction https://www.software.hixie.ch/utilities/js/live-dom-viewer/?saved=12477 which only Blink is consistent). |
As another data-point, we've received another web developer bug report about our current (min-intrinsic) behaviour being perceived as incorrect while the min-content behaviour perceived as correct. It's more or less this case: Agenda+ to move to the min-content behaviour. |
The CSS Working Group just discussed
The full IRC log of that discussion<emilio> iank_: this is re auto min size on flex items and aspect-ratio<emilio> ... blink is more or less consistently dropping the aspect-ratio <emilio> ... other browsers are sometimes dropping it <emilio> ... blink has been on the receiving end of a bunch of web dev bug reports <emilio> ... this situation isn't good for web devs <emilio> ... haven't seem bug reports for the other engines <emilio> ... as such I think we would do a change to respect aspect-ratio <emilio> ... we can add a bunch of tentative tests about this behavior <emilio> ... proposal would be max(aspect-ratio, min-intrinsic size) <TabAtkins> I'm happy to take the change, I'll just have to spend some time digesting exactly what it is. But if we're getting compat issues and webdevs are preferring one behavior, let's do it. <dholbert> s/aspect-ratio/transferred-size/ <dholbert> (in the min() expression) <dholbert> (er max() expression) <emilio> fantasai: I'd like to <fantasai> s/I'd like to/I'm the same as Tab here/ <emilio> ... TabAtkins and I would like to spend some time on this issue, but if there are compat issues... <emilio> iank_: Yeah I'm going to try changing blink and add tests <emilio> fantasai: I think I understand the proposal now <emilio> ... I think it makes sense? <chrishtr> +1 to accepting the change <emilio> astearns: should we resolve on accepting this change tentatively? <emilio> q+ <astearns> ack emilio <emilio> iank_: what's going on is web devs really hate it when the aspect-ratio gets dropped <emilio> q+ <emilio> iank_: I think proposed resolution would be to change the AMS of flex items to be max(min-intrinsic-size, transferred-size via aspect-ratio) <astearns> ack emilio <fantasai> fantasai: ok, got it <fantasai> emilio: Do we understand what Gecko and WebKit are doing? <fantasai> iank_: I understand, it's complicated <fantasai> iank_: WebKit and Gecko are inconsistent between row/column axes, and aren't consistent in when transferred size is applied. <emilio> they are inconsistent between column / row and how the transferred size is getting applied <fantasai> iank_: everyone is super inconsistent <fantasai> emilio: if you could write it up, I'd be curious <fantasai> iank_: my intention was to write out a suite of testcases for this behavior <fantasai> iank_: that should show what's happening <fantasai> iank_: issue is that Web devs are running into behavior where WEbkit/Gecko are consistent in honoring aspect ratio and Blink isn't <fantasai> emilio: so your proposal would be breaking changes for all three engines <fantasai> emilio: right? <fantasai> iank_: yes, because we're all inconsistent. And inconsistent across axes. Basically everyone is bad. <fantasai> iank_: we're probalby the most consistent, but not what web devs expect <fantasai> iank_: so that's where we are <fantasai> emilio: ok, this sounds good. We'll look at tests. On paper sounds reasonable. <fantasai> iank_: given lack of bug reports on other engines, not worried <fantasai> astearns: Proposed resolution to change minimum size of flex to be the larger of min-intrinsic and transferred size <emilio> PROPOSED: change the AMS of flex items to be max(min-intrinsic-size, transferred-size via aspect-ratio) <emilio> RESOLVED: change minimum size of flex items to be the larger of min-intrinsic and transferred size |
https://drafts.csswg.org/css-flexbox/#min-size-auto
This issue stems from an interop problem discussed in web-platform-tests/wpt@21a7c47 .
In the example below, the spec dictates a final width of the flex item of
50px
. But when the same element is a block box it has width100px
. Should they be different?https://jsfiddle.net/dgrogan/2734sdfr/
Of course a flex item can have a different final size than an otherwise-identical block box because the whole point of a flex container is that it flexes the items. But this item is not flexed, and it's still a different size. That seems weird.
In more detail, the difference in this case is a result of aspect-ratio's automatic minimum size being more aggressive than flexbox's. Giving flex a weaker set of constraints makes sense, because we want to give flexbox the power to flex its items. But it is puzzlement-inducing that putting a no-op flex container around an element changes the element's size.
Possible solution if we want the boxes to be the same width whether they are block boxes or unflexed flex items (i.e. Firefox's behavior today):
Or, do whatever Firefox is doing, which is probably not those.
But, if giving the blue box different sizes in the two layout modes doesn't strike anyone else as weird, then maybe we just close this issue and discard the idea of making content-size suggestion = min-intrinsic. Even if we do that, we still need to determine which of Firefox and Chrome behavior is correct.
[1] or whatever the name is, vis-a-vis #5305
The text was updated successfully, but these errors were encountered: