You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[css-grid] Stretching tracks fails to feed back into sizing algorithm #1150
Here to resolve the size of the auto column, we check our children.
auto is somehow equivalent to minmax(auto, max-content).
The image has width: 100%; which cannot be resolved as the column has auto size, so for the minimum track size we consider 0px. And we use 50px, the content size of the image as maximum track size. And for the row, we use 50px too (the content size of the image).
Then the column size is affected by the default justify-content: stretch; which makes the auto column to grow up to 200px. The image is sized against that size of the column, so it ends up being 200x200. However the row is still 50px.
The row here being 50px is not very helpful. It should respond to the stretching of the track.
The responsible spec prose is in https://drafts.csswg.org/css-grid/#algo-overview where stretch is processed at the end of the grid sizing algorithm. It should instead be integrated as a final step of track sizing, after fr sizing, in order to be looped into later track-sizing passes.
With the current spec stretch is done at the end of the grid track sizing algorithm. So this case works like:
On the 1st pass for the columns, the width is calculated as 100px for both columns (the items are vertical).
The pass for rows it's straight forward, as the row has a fixed size of 250px.
Then the min-content contribution of the 1st item has changed due to the row size, so we need to do a 2nd pass. On the 2nd pass for the columns, the width is calculated as 300px for the 1st column and 100px for the 2nd one.
Again the rows pass is simple as it's a fixed size.
Then we do stretch so the 1st column becomes 350px and the 2nd column 150px.
However, with the new proposal I believe this will end up in a worse result:
The 1st pass for columns is the same. 100px width for both.
But then we do stretch, so each column becomes 250px.
Then the pass for rows is again simple as it has a fixed size of 250px.
As the min-content contribution of the first item has changed again we need a new pass. On the 2nd pass for columns the 1st column has a width of 300px, and the 2nd one keeps its 250px width (the item was already sized using the 250px of that column after the stretch. And here's the problem we'll have overflow on the grid container, because of the stretch done in step 2.
As you can see in the picture, in the last case we'll be overflowing the grid container because of stretch, which feels really wrong as stretch should use the available space not more.
Last, I'm not sure if the use case is important enough to introduce changes on the track sizing algorithm at this stage. If you're using percentages on items against indefinite track sizes, I guess that having weird results in some cases can be somehow expected.
Fixed max track sizes in the row axis are assumed at the beginning of the first column sizing pass, so the second interpretation can't happen in any case. Note the second paragraph:
First, the track sizing algorithm is used to resolve the sizes of the grid columns.
If calculating the layout of a grid item in this step depends on the available space in the block axis, assume the available space that it would have if any row with a definite max track sizing function had that size and all other rows were infinite.
A case where we could get this result would be if the grid container itself had a fixed height.
A second comment is, if we're recalculating the column sizes, shouldn't the extra space from stretching be re-calculated? In which case we should still get the first result.
The CSS Working Group just discussed Stretching tracks fails to feed back into sizing algorithm, and agreed to the following resolutions:
RESOLVED: integrate stretching into track sizing algo
The full IRC log of that discussion
<dauwhe> Topic: Stretching tracks fails to feed back into sizing algorithm
<astearns> github: https://github.com//issues/1150
<dauwhe> fantasai: the issue here is that the stretch alignment property takes effect
<dauwhe> ... at the end of the algo
<dauwhe> ... you size the cols, then use size of cols to set height of rows
<dauwhe> ... at the end you do alignment
<dauwhe> ... that's generally fine
<dauwhe> ... cause alignment don't change track sizes
<dauwhe> ... but stretch does
<dauwhe> ... if you start with this example, you have image with intrinsic size, col sizes to intrinsic size, then try to size the rows
<dauwhe> ... and we use the size of the columns because there's an aspect ratio
<dauwhe> ... and now the item that's 100% wide fills the track in that axis, but then overflows the row
<dauwhe> ... the suggestion is that the stretching phase should be accounted for in the sizing algo
<dauwhe> TabAtkins: makes sense
<dauwhe> fantasai: we'll try to incorporate this into the algo, then will bring to group for review
<dauwhe> TabAtkins: is auto track and stretch distro the only thing that does this?
<dauwhe> fantasai: yes
<dauwhe> TabAtkins: then this makes total sense
<dauwhe> fantasai: the proposal is to handle the streching at each phase of stretch sizing
<dauwhe> astearns: would it make sense to have a note in align?
<dauwhe> fantasai: flex already has this
<fantasai> s/this/this kind of integration/
<dauwhe> Rossen: stretching and last baseline tend to have feedback back into the layout algo
<fantasai> astearns: Yeah, so should have a note pointing to the appropriate section of grid/flex
<dauwhe> RESOLVED: integrate stretching into track sizing algo
<dauwhe> fantasai: ONE MORE THING
A case where we could get this result would be if the grid container itself had a fixed height.
Yep, you're right that I missed the part of the algorithm that explains that we'll be using the fixed max track size, so that case is not an issue.
Also if we go for the case where the row is auto but the grid container has height: 250px the issue is not present either, as due to the orthogonal item we do a 2nd pass and everything works as expected.
I've been doing some experiments and it seems that it works as expected and I didn't find any case that breaks due to this. Of course this need more testing but it seems a good approach.
It's always scary to touch the track sizing algorithm, but let's hope everything goes right. 😄
Regarding the prose, it seems there are 2 verbs together in:
Activity
mrego commentedon Apr 3, 2017
I'm not sure if this will be possible without introducing other issues. For example in the case of orthogonal flows.
Let's try to illustrate that with the following example:
With the current spec
stretchis done at the end of the grid track sizing algorithm. So this case works like:min-contentcontribution of the 1st item has changed due to the row size, so we need to do a 2nd pass. On the 2nd pass for the columns, the width is calculated as 300px for the 1st column and 100px for the 2nd one.stretchso the 1st column becomes 350px and the 2nd column 150px.However, with the new proposal I believe this will end up in a worse result:
stretch, so each column becomes 250px.min-contentcontribution of the first item has changed again we need a new pass. On the 2nd pass for columns the 1st column has a width of 300px, and the 2nd one keeps its 250px width (the item was already sized using the 250px of that column after thestretch. And here's the problem we'll have overflow on the grid container, because of thestretchdone in step 2.As you can see in the picture, in the last case we'll be overflowing the grid container because of
stretch, which feels really wrong asstretchshould use the available space not more.Last, I'm not sure if the use case is important enough to introduce changes on the track sizing algorithm at this stage. If you're using percentages on items against indefinite track sizes, I guess that having weird results in some cases can be somehow expected.
fantasai commentedon Aug 1, 2017
Fixed max track sizes in the row axis are assumed at the beginning of the first column sizing pass, so the second interpretation can't happen in any case. Note the second paragraph:
A case where we could get this result would be if the grid container itself had a fixed height.
A second comment is, if we're recalculating the column sizes, shouldn't the extra space from stretching be re-calculated? In which case we should still get the first result.
css-meeting-bot commentedon Aug 4, 2017
The CSS Working Group just discussed
Stretching tracks fails to feed back into sizing algorithm, and agreed to the following resolutions:RESOLVED: integrate stretching into track sizing algoThe full IRC log of that discussion
<dauwhe> Topic: Stretching tracks fails to feed back into sizing algorithm<astearns> github: https://github.com//issues/1150
<dauwhe> fantasai: the issue here is that the stretch alignment property takes effect
<dauwhe> ... at the end of the algo
<dauwhe> ... you size the cols, then use size of cols to set height of rows
<dauwhe> ... at the end you do alignment
<dauwhe> ... that's generally fine
<dauwhe> ... cause alignment don't change track sizes
<dauwhe> ... but stretch does
<dauwhe> ... if you start with this example, you have image with intrinsic size, col sizes to intrinsic size, then try to size the rows
<dauwhe> ... and we use the size of the columns because there's an aspect ratio
<dauwhe> ... and now the item that's 100% wide fills the track in that axis, but then overflows the row
<dauwhe> ... the suggestion is that the stretching phase should be accounted for in the sizing algo
<dauwhe> TabAtkins: makes sense
<dauwhe> fantasai: we'll try to incorporate this into the algo, then will bring to group for review
<dauwhe> TabAtkins: is auto track and stretch distro the only thing that does this?
<dauwhe> fantasai: yes
<dauwhe> TabAtkins: then this makes total sense
<dauwhe> fantasai: the proposal is to handle the streching at each phase of stretch sizing
<dauwhe> astearns: would it make sense to have a note in align?
<dauwhe> fantasai: flex already has this
<fantasai> s/this/this kind of integration/
<dauwhe> Rossen: stretching and last baseline tend to have feedback back into the layout algo
<fantasai> astearns: Yeah, so should have a note pointing to the appropriate section of grid/flex
<dauwhe> RESOLVED: integrate stretching into track sizing algo
<dauwhe> fantasai: ONE MORE THING
fantasai commentedon Aug 9, 2017
Edits checked in. @mrego, please let us know if anything doesn't seem right to you?
mrego commentedon Sep 8, 2017
Yep, you're right that I missed the part of the algorithm that explains that we'll be using the fixed max track size, so that case is not an issue.
Also if we go for the case where the row is
autobut the grid container hasheight: 250pxthe issue is not present either, as due to the orthogonal item we do a 2nd pass and everything works as expected.I've been doing some experiments and it seems that it works as expected and I didn't find any case that breaks due to this. Of course this need more testing but it seems a good approach.
It's always scary to touch the track sizing algorithm, but let's hope everything goes right. 😄
Regarding the prose, it seems there are 2 verbs together in:
[css-grid] Move stretch of "auto" tracks into the track sizing algorithm
[css-grid] Move stretch of "auto" tracks into the track sizing algorithm
[css-grid] Move stretch of "auto" tracks into the track sizing algorithm
[css-grid] Move stretch of "auto" tracks into the track sizing algorithm
[css-grid] Move stretch of "auto" tracks into the track sizing algorithm
[css-grid] Move stretch of "auto" tracks into the track sizing algorithm
[css-grid] Move stretch of "auto" tracks into the track sizing algorithm
[css-grid] Move stretch of "auto" tracks into the track sizing algorithm
[css-grid] Stretching auto tracks should be done as part of the track…
[css-grid] Move stretch of "auto" tracks into the track sizing algorithm
mrego commentedon Oct 13, 2017
JFTR, this seems to have caused a new issue #1866.
Merge r221931 - [css-grid] Stretching auto tracks should be done as p…
[css-grid] Move stretch of "auto" tracks into the track sizing algorithm
[css-grid] Move stretch of "auto" tracks into the track sizing algorithm
[css-grid] Stretching auto tracks should be done as part of the track…
Merge r221931 - [css-grid] Stretching auto tracks should be done as p…