Skip to content

Size a wrapping row's min-content width by its widest child (#2104) - #60509

Merged
meta-codesync[bot] merged 1 commit into
react:mainfrom
javache:export-D135341618
Dec 3, 2026
Merged

meta-codesync[bot] merged 1 commit into
react:mainfrom
javache:export-D135341618

Conversation

@javache

@javache javache commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

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:

<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

@meta-codesync

meta-codesync Bot commented Dec 3, 2026

Copy link
Copy Markdown

@javache has exported this pull request. If you are a Meta employee, you can view the originating Diff in D135341618.

@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Dec 3, 2026
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>
@meta-codesync
meta-codesync Bot merged commit f11445a into react:main Dec 3, 2026
64 of 66 checks passed
@react-native-bot

Copy link
Copy Markdown
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?

@react-native-bot react-native-bot added the Merged This PR has been merged. label Dec 3, 2026
@javache
javache deleted the export-D135341618 branch December 4, 2026 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged This PR has been merged. Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants