Repository navigation
Size a wrapping row's min-content width by its widest child (#2104) - #60509
Merged
Merged
Conversation
|
@javache has exported this pull request. If you are a Meta employee, you can view the originating Diff in D135341618. |
Summary:
Why
===
A flex item does not shrink below its min-content size (css-flexbox-1 §4.5). A wrapping row can put each child on a line of its own, so its min-content width is that of its widest child (§9.9.1: "for a multi-line container, the min-content main size is simply the largest min-content contribution of all the non-collapsed flex items"). Yoga's walk sums the children whether or not the container wraps, so a wrapping row never narrows enough to wrap:
```html
<div style="display: flex; width: 200px">
<div style="display: flex; flex-wrap: wrap; flex-shrink: 1; gap: 20px">
<!-- Chrome: 70px wide, two lines. Yoga: 140px wide, one line -->
<div style="width: 50px; height: 10px"></div>
<div style="width: 60px; height: 10px; margin: 0 5px"></div>
</div>
<div style="width: 180px; flex-shrink: 0"></div>
</div>
```
How
===
The walk takes the largest child, and no gaps, along the main axis of a wrapping row.
A wrapping column keeps the sum, which differs from §9.9.1: its sentence covers both directions. Chrome finds a min-content height by laying the box out at an indefinite height, where a column never wraps, as css-sizing-3 §2.1 has it for block containers (the min-content block size equals the max-content block size). `wrapping_column_counts_all_children` records this. Only Chrome was checked.
The min-content height of a wrapping row is not addressed. It depends on where the row's lines break, which the walk cannot know. The walk still takes the tallest child, so a column can shrink a wrapping row below the lines it wraps to.
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, `wrapping_row_counts_widest_child` fails: the row is 140 wide and 10 tall where Chrome has 70 and 40. `wrapping_column_counts_all_children` passes with and without the change (110 tall), and fails with 60 if the rule also applies to columns.
`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 keeping a wrapping row as wide as all of its children
Differential Revision: D135341618
Signed-off-by: James Ide <ide@expo.dev>
javache
force-pushed
the
export-D135341618
branch
from
December 3, 2026 16:01
ed46a55 to
ef79f31
Compare
Collaborator
|
This pull request was successfully merged by @javache in f11445a 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). A wrapping row can put each child on a line of its own, so its min-content width is that of its widest child (§9.9.1: "for a multi-line container, the min-content main size is simply the largest min-content contribution of all the non-collapsed flex items"). Yoga's walk sums the children whether or not the container wraps, so a wrapping row never narrows enough to wrap:
How
The walk takes the largest child, and no gaps, along the main axis of a wrapping row.
A wrapping column keeps the sum, which differs from §9.9.1: its sentence covers both directions. Chrome finds a min-content height by laying the box out at an indefinite height, where a column never wraps, as css-sizing-3 §2.1 has it for block containers (the min-content block size equals the max-content block size).
wrapping_column_counts_all_childrenrecords this. Only Chrome was checked.The min-content height of a wrapping row is not addressed. It depends on where the row's lines break, which the walk cannot know. The walk still takes the tallest child, so a column can shrink a wrapping row below the lines it wraps to.
Test Plan
yarn gentest -f YGAutoMinSizeTestgenerates the new fixtures from Chrome, andcmake --build tests/build && tests/build/yogatestspasses.With the change reverted,
wrapping_row_counts_widest_childfails: the row is 140 wide and 10 tall where Chrome has 70 and 40.wrapping_column_counts_all_childrenpasses with and without the change (110 tall), and fails with 60 if the rule also applies to columns.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 keeping a wrapping row as wide as all of its children
Differential Revision: D135341618
Signed-off-by: James Ide ide@expo.dev