Repository navigation
Count gaps in a flex container's min-content size (#2103) - #60512
Merged
Merged
Conversation
Summary:
Why
===
A flex item does not shrink below its min-content size (css-flexbox-1 §4.5). When the item is itself a flex container, Chrome counts the gaps between its children along its main axis in that size. Yoga's min-content walk leaves them out, so the item can shrink until its children overflow it by the gaps:
```html
<div style="display: flex; width: 200px">
<div style="display: flex; flex-shrink: 1; gap: 20px"> <!-- Chrome: 130px. Yoga: 90px -->
<div style="width: 30px; flex-shrink: 0"></div>
<div style="width: 30px; flex-shrink: 0"></div>
<div style="width: 30px; flex-shrink: 0"></div>
</div>
<div style="width: 180px; flex-shrink: 0"></div>
</div>
```
How
===
The walk adds one gap between each two in-flow children when it sums them along the container's main axis. A percentage gap counts as zero, because a percentage gutter resolves against zero for an intrinsic size contribution (css-sizing-3 §5.2.1). Chrome does the same.
Test Plan
=========
`yarn gentest -f YGAutoMinSizeTest` generates the new fixtures from Chrome, and `cmake --build tests/build && tests/build/yogatests` passes.
With the change reverted, two fixtures fail:
| Fixture | Chrome | Without the change |
| --- | --- | --- |
| `counts_column_gaps` (item width) | 130 | 90 |
| `counts_row_gaps` (item height) | 80 | 60 |
`gaps_skip_cross_axis_and_absolute_children` and `percent_gap_counts_as_zero` pass with and without the change; they pin what must not count. Adding cross-axis gaps, counting an absolutely positioned child, or resolving a percentage gap against the owner's width makes one of them fail (50 becomes 70, 30 becomes 50, and 60 becomes 80).
`yarn gentest -h` leaves the tree clean, and `node ./scripts/clang-format.js --check` passes. The generated Java tests were not run, because the Gradle project has no unit-test source set, and neither were the generated JavaScript tests, which need Emscripten.
Changelog:
[General][Fixed] - Fix Yoga's automatic minimum size leaving out the gaps between a flex item's children
Reviewed By: javache
Differential Revision: D135335463
|
@javache has exported this pull request. If you are a Meta employee, you can view the originating Diff in D135335463. |
Collaborator
|
This pull request was successfully merged by @javache in 9b68cb1 When will my fix make it into a release? | How to file a pick request? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Why
A flex item does not shrink below its min-content size (css-flexbox-1 §4.5). When the item is itself a flex container, Chrome counts the gaps between its children along its main axis in that size. Yoga's min-content walk leaves them out, so the item can shrink until its children overflow it by the gaps:
How
The walk adds one gap between each two in-flow children when it sums them along the container's main axis. A percentage gap counts as zero, because a percentage gutter resolves against zero for an intrinsic size contribution (css-sizing-3 §5.2.1). Chrome does the same.
Test Plan
yarn gentest -f YGAutoMinSizeTestgenerates the new fixtures from Chrome, andcmake --build tests/build && tests/build/yogatestspasses.With the change reverted, two fixtures fail:
counts_column_gaps(item width)counts_row_gaps(item height)gaps_skip_cross_axis_and_absolute_childrenandpercent_gap_counts_as_zeropass with and without the change; they pin what must not count. Adding cross-axis gaps, counting an absolutely positioned child, or resolving a percentage gap against the owner's width makes one of them fail (50 becomes 70, 30 becomes 50, and 60 becomes 80).yarn gentest -hleaves the tree clean, andnode ./scripts/clang-format.js --checkpasses. The generated Java tests were not run, because the Gradle project has no unit-test source set, and neither were the generated JavaScript tests, which need Emscripten.Changelog:
[General][Fixed] - Fix Yoga's automatic minimum size leaving out the gaps between a flex item's children
Reviewed By: javache
Differential Revision: D135335463