Skip to content

Count gaps in a flex container's min-content size (#2103) - #60512

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

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

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). 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:

<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

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
@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 D135335463.

@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
@github-actions github-actions Bot removed 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
@meta-codesync
meta-codesync Bot merged commit 9b68cb1 into react:main Dec 3, 2026
82 of 84 checks passed
@react-native-bot

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

@react-native-bot react-native-bot added the Merged This PR has been merged. label Dec 3, 2026
@javache
javache deleted the export-D135335463 branch December 3, 2026 15:52
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-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants