Skip to content

Count the sizes nested boxes state in automatic minimum sizes (#2101) - #60483

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

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

Conversation

@javache

@javache javache commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Summary:

  • Count the sizes nested boxes state in automatic minimum sizes

Why

With automatic minimum sizes on (YGErrataMinSizeUndefinedInsteadOfAuto off), a flex item does not shrink below its min-content size (css-flexbox-1 §4.5). That size is built from its children's min-content contributions (css-sizing-3 §5.2), and a child that states a size contributes that size. Yoga's min-content walk reads only content (measure functions, padding, border, margins) and ignores width, height, min-*, max-* and aspect-ratio on everything below the item:

<div style="display: flex; width: 200px">
  <div style="display: flex; flex-shrink: 1">     <!-- Chrome: 100px. Yoga: 20px -->
    <div style="width: 100px; height: 10px; flex-shrink: 0"></div>
  </div>
  <div style="width: 180px; flex-shrink: 0"></div>
</div>

How

The walk takes each child's min-content contribution along the axis it is asked for:

  • the size the child states, with its padding and border for a content-box size;
  • otherwise its content's min-content size, as before, or, where larger, the size its aspect ratio transfers from the size it states on the other axis (css-sizing-4);
  • clamped to the minimum and maximum it states, and no less than its padding and border (boundAxis).

A percentage size, minimum or maximum depends on the size being found, so it behaves as auto or as no limit (css-sizing-3 §5.2.1). A child that states its size on an axis is not measured, walked or cloned for that axis. The item's own specified size suggestion is unchanged.

The walk still differs from the specifications or from Chrome in these ways:

  • A child's flex-basis and flex factors are not read. css-flexbox-1 §9.9.3 caps a flex item's contribution at its flex base size if it cannot grow and floors it there if it cannot shrink, and Chrome counts a definite flex basis for a child that cannot shrink. An item around a flex: 0 0 70px child is 70px in Chrome; with this change and without it, the item is the size of the child's content.
  • §9.9.3 also takes the larger of a flex item's min-content size and its stated size. The walk takes the stated size, as css-sizing-3 does. For a child that cannot grow, the cap gives the same result (child_width_smaller_than_content: 20px in Chrome). Chrome was not checked for a child that can grow.
  • A display: contents child is still walked, and counted, as a box of its own.
  • A percentage padding or margin resolves against the owner's width, as it does elsewhere in the walk. Chrome resolves it against zero for an intrinsic contribution (css-sizing-3 §5.2.1): a content-box child with width: 30px; padding-left: 10% contributes 30px in Chrome and 50px under a 200px owner in Yoga. Following Chrome would remove most of the walk's owner-width memo key, so it belongs in a change of its own.
  • The aspect-ratio transfer uses the border-box size, also for a content-box child.

container_min_content_memo_respects_owner_width relied on a 20px spacer not counting toward its parent's min-content size. The parent now has max-width: 70px, which keeps the two probes the test compares apart.

Test Plan

yarn gentest -f YGAutoMinSizeTest generates the new fixtures in YGAutoMinSizeTest.html from Chrome. cmake --build tests/build && tests/build/yogatests passes with them and with the hand-written tests for whether the probe runs and for the memo.

With the change to CalculateLayout.cpp reverted, every new test fails. The width or height of the shrinking item, in Chrome and without the change:

Fixture Chrome Without the change
counts_child_width 100 20
counts_child_height 100 20
counts_widest_child_of_column 60 20
item_width_larger_than_content 30 10
child_width_larger_than_content 100 20
child_width_smaller_than_content 20 10
child_min_width 50 20
child_max_width 40 20
child_percent_width 30 20
child_content_box_width 66 20
child_padding_exceeds_width 40 20
child_aspect_ratio 60 20
child_aspect_ratio_column 60 20
counts_content_of_overflow_hidden_child 130 60

child_with_stated_size_skips_min_content_probe sees 2 probes where it expects none, and stated_size_with_percentage_padding_follows_owner_width sees 10 and 0 where it expects 50 and 40.

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 ignoring the width, height, min/max sizes and aspect ratio of boxes inside a flex item

  • Mark percentage padding in a child's min-content contribution

An empty child, or one with a static min-content size, reports a
contribution that does not depend on the owner's width, but boundAxis then
floors it at the child's padding and border. With a percentage padding the
result depends on the owner's width, so the memo of the container around it
has to be keyed on that width.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com


Wearable integration

The wearable UI adapter retains zero automatic minima for unmeasured, untyped app boxes and size-contained boxes, without disabling Yoga's native WSS and measured-text minima. Explicit minima remain authoritative; containment and type-rule changes remap both minimum axes so compatibility defaults do not persist after they stop applying.

Differential Revision: D135304422

…2101)

Summary:
* Count the sizes nested boxes state in automatic minimum sizes

Why
===
With automatic minimum sizes on (`YGErrataMinSizeUndefinedInsteadOfAuto` off), a flex item does not shrink below its min-content size (css-flexbox-1 §4.5). That size is built from its children's min-content contributions (css-sizing-3 §5.2), and a child that states a size contributes that size. Yoga's min-content walk reads only content (measure functions, padding, border, margins) and ignores `width`, `height`, `min-*`, `max-*` and `aspect-ratio` on everything below the item:

```html
<div style="display: flex; width: 200px">
  <div style="display: flex; flex-shrink: 1">     <!-- Chrome: 100px. Yoga: 20px -->
    <div style="width: 100px; height: 10px; flex-shrink: 0"></div>
  </div>
  <div style="width: 180px; flex-shrink: 0"></div>
</div>
```

How
===
The walk takes each child's min-content contribution along the axis it is asked for:

- the size the child states, with its padding and border for a content-box size;
- otherwise its content's min-content size, as before, or, where larger, the size its aspect ratio transfers from the size it states on the other axis (css-sizing-4);
- clamped to the minimum and maximum it states, and no less than its padding and border (`boundAxis`).

A percentage size, minimum or maximum depends on the size being found, so it behaves as `auto` or as no limit (css-sizing-3 §5.2.1). A child that states its size on an axis is not measured, walked or cloned for that axis. The item's own specified size suggestion is unchanged.

The walk still differs from the specifications or from Chrome in these ways:

- A child's `flex-basis` and flex factors are not read. css-flexbox-1 §9.9.3 caps a flex item's contribution at its flex base size if it cannot grow and floors it there if it cannot shrink, and Chrome counts a definite flex basis for a child that cannot shrink. An item around a `flex: 0 0 70px` child is 70px in Chrome; with this change and without it, the item is the size of the child's content.
- §9.9.3 also takes the larger of a flex item's min-content size and its stated size. The walk takes the stated size, as css-sizing-3 does. For a child that cannot grow, the cap gives the same result (`child_width_smaller_than_content`: 20px in Chrome). Chrome was not checked for a child that can grow.
- A `display: contents` child is still walked, and counted, as a box of its own.
- A percentage padding or margin resolves against the owner's width, as it does elsewhere in the walk. Chrome resolves it against zero for an intrinsic contribution (css-sizing-3 §5.2.1): a content-box child with `width: 30px; padding-left: 10%` contributes 30px in Chrome and 50px under a 200px owner in Yoga. Following Chrome would remove most of the walk's owner-width memo key, so it belongs in a change of its own.
- The aspect-ratio transfer uses the border-box size, also for a content-box child.

`container_min_content_memo_respects_owner_width` relied on a 20px spacer not counting toward its parent's min-content size. The parent now has `max-width: 70px`, which keeps the two probes the test compares apart.

Test Plan
=========
`yarn gentest -f YGAutoMinSizeTest` generates the new fixtures in `YGAutoMinSizeTest.html` from Chrome. `cmake --build tests/build && tests/build/yogatests` passes with them and with the hand-written tests for whether the probe runs and for the memo.

With the change to `CalculateLayout.cpp` reverted, every new test fails. The width or height of the shrinking item, in Chrome and without the change:

| Fixture | Chrome | Without the change |
| --- | --- | --- |
| `counts_child_width` | 100 | 20 |
| `counts_child_height` | 100 | 20 |
| `counts_widest_child_of_column` | 60 | 20 |
| `item_width_larger_than_content` | 30 | 10 |
| `child_width_larger_than_content` | 100 | 20 |
| `child_width_smaller_than_content` | 20 | 10 |
| `child_min_width` | 50 | 20 |
| `child_max_width` | 40 | 20 |
| `child_percent_width` | 30 | 20 |
| `child_content_box_width` | 66 | 20 |
| `child_padding_exceeds_width` | 40 | 20 |
| `child_aspect_ratio` | 60 | 20 |
| `child_aspect_ratio_column` | 60 | 20 |
| `counts_content_of_overflow_hidden_child` | 130 | 60 |

`child_with_stated_size_skips_min_content_probe` sees 2 probes where it expects none, and `stated_size_with_percentage_padding_follows_owner_width` sees 10 and 0 where it expects 50 and 40.

`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 ignoring the width, height, min/max sizes and aspect ratio of boxes inside a flex item

* Mark percentage padding in a child's min-content contribution

An empty child, or one with a static min-content size, reports a
contribution that does not depend on the owner's width, but boundAxis then
floors it at the child's padding and border. With a percentage padding the
result depends on the owner's width, so the memo of the container around it
has to be keyed on that width.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Wearable integration
====================
The wearable UI adapter retains zero automatic minima for unmeasured, untyped app boxes and size-contained boxes, without disabling Yoga's native WSS and measured-text minima. Explicit minima remain authoritative; containment and type-rule changes remap both minimum axes so compatibility defaults do not persist after they stop applying.

Differential Revision: D135304422
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 2, 2026
@facebook-github-tools facebook-github-tools Bot added p: Facebook Partner: Facebook Partner labels Dec 2, 2026
@meta-codesync

meta-codesync Bot commented Dec 2, 2026

Copy link
Copy Markdown

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

meta-codesync Bot pushed a commit to meta/litho that referenced this pull request Dec 3, 2026
Summary:
X-link: react/react-native#60483

* Count the sizes nested boxes state in automatic minimum sizes

Why
===
With automatic minimum sizes on (`YGErrataMinSizeUndefinedInsteadOfAuto` off), a flex item does not shrink below its min-content size (css-flexbox-1 §4.5). That size is built from its children's min-content contributions (css-sizing-3 §5.2), and a child that states a size contributes that size. Yoga's min-content walk reads only content (measure functions, padding, border, margins) and ignores `width`, `height`, `min-*`, `max-*` and `aspect-ratio` on everything below the item:

```html
<div style="display: flex; width: 200px">
  <div style="display: flex; flex-shrink: 1">     <!-- Chrome: 100px. Yoga: 20px -->
    <div style="width: 100px; height: 10px; flex-shrink: 0"></div>
  </div>
  <div style="width: 180px; flex-shrink: 0"></div>
</div>
```

How
===
The walk takes each child's min-content contribution along the axis it is asked for:

- the size the child states, with its padding and border for a content-box size;
- otherwise its content's min-content size, as before, or, where larger, the size its aspect ratio transfers from the size it states on the other axis (css-sizing-4);
- clamped to the minimum and maximum it states, and no less than its padding and border (`boundAxis`).

A percentage size, minimum or maximum depends on the size being found, so it behaves as `auto` or as no limit (css-sizing-3 §5.2.1). A child that states its size on an axis is not measured, walked or cloned for that axis. The item's own specified size suggestion is unchanged.

The walk still differs from the specifications or from Chrome in these ways:

- A child's `flex-basis` and flex factors are not read. css-flexbox-1 §9.9.3 caps a flex item's contribution at its flex base size if it cannot grow and floors it there if it cannot shrink, and Chrome counts a definite flex basis for a child that cannot shrink. An item around a `flex: 0 0 70px` child is 70px in Chrome; with this change and without it, the item is the size of the child's content.
- §9.9.3 also takes the larger of a flex item's min-content size and its stated size. The walk takes the stated size, as css-sizing-3 does. For a child that cannot grow, the cap gives the same result (`child_width_smaller_than_content`: 20px in Chrome). Chrome was not checked for a child that can grow.
- A `display: contents` child is still walked, and counted, as a box of its own.
- A percentage padding or margin resolves against the owner's width, as it does elsewhere in the walk. Chrome resolves it against zero for an intrinsic contribution (css-sizing-3 §5.2.1): a content-box child with `width: 30px; padding-left: 10%` contributes 30px in Chrome and 50px under a 200px owner in Yoga. Following Chrome would remove most of the walk's owner-width memo key, so it belongs in a change of its own.
- The aspect-ratio transfer uses the border-box size, also for a content-box child.

`container_min_content_memo_respects_owner_width` relied on a 20px spacer not counting toward its parent's min-content size. The parent now has `max-width: 70px`, which keeps the two probes the test compares apart.

Test Plan
=========
`yarn gentest -f YGAutoMinSizeTest` generates the new fixtures in `YGAutoMinSizeTest.html` from Chrome. `cmake --build tests/build && tests/build/yogatests` passes with them and with the hand-written tests for whether the probe runs and for the memo.

With the change to `CalculateLayout.cpp` reverted, every new test fails. The width or height of the shrinking item, in Chrome and without the change:

| Fixture | Chrome | Without the change |
| --- | --- | --- |
| `counts_child_width` | 100 | 20 |
| `counts_child_height` | 100 | 20 |
| `counts_widest_child_of_column` | 60 | 20 |
| `item_width_larger_than_content` | 30 | 10 |
| `child_width_larger_than_content` | 100 | 20 |
| `child_width_smaller_than_content` | 20 | 10 |
| `child_min_width` | 50 | 20 |
| `child_max_width` | 40 | 20 |
| `child_percent_width` | 30 | 20 |
| `child_content_box_width` | 66 | 20 |
| `child_padding_exceeds_width` | 40 | 20 |
| `child_aspect_ratio` | 60 | 20 |
| `child_aspect_ratio_column` | 60 | 20 |
| `counts_content_of_overflow_hidden_child` | 130 | 60 |

`child_with_stated_size_skips_min_content_probe` sees 2 probes where it expects none, and `stated_size_with_percentage_padding_follows_owner_width` sees 10 and 0 where it expects 50 and 40.

`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 ignoring the width, height, min/max sizes and aspect ratio of boxes inside a flex item

* Mark percentage padding in a child's min-content contribution

An empty child, or one with a static min-content size, reports a
contribution that does not depend on the owner's width, but boundAxis then
floors it at the child's padding and border. With a percentage padding the
result depends on the owner's width, so the memo of the container around it
has to be keyed on that width.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Reviewed By: bilalsou

Differential Revision: D135304422

fbshipit-source-id: a40246566c9bfffdea25e0eb507622577a4efa74

Co-authored-by: intergalacticspacehighway <nishanbende@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@meta-codesync
meta-codesync Bot merged commit 9f8fcca into react:main Dec 3, 2026
111 of 119 checks passed
@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @javache in 9f8fcca

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants