Skip to content

Walk only the requested axis for a container's min-content size (#2102) - #60481

Open
javache wants to merge 2 commits into
react:mainfrom
javache:export-D135328393
Open

javache wants to merge 2 commits into
react:mainfrom
javache:export-D135328393

Conversation

@javache

@javache javache commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Summary:

  • Walk only the requested axis for a container's min-content size

Why

The min-content walk behind automatic minimum sizes (css-flexbox-1 §4.5) is asked for a container's size on one axis. For every child it computed the size on both of the container's axes, summed one, took the largest of the other, and returned only the one it was asked for. The work on the other axis was wasted: a leaf was measured, and a container walked, on an axis no flex line needed.

How

The walk asks each child for the requested axis alone. It sums the children where that is the container's main axis and takes the largest where it is the cross axis. Layout results are unchanged. The memo already kept a leaf to one probe per axis per layout, so the saving is one measure call per leaf, and one walk per container, on the axis nobody asked for.

Test Plan

cmake --build tests/build && tests/build/yogatests passes. nested_leaf_probed_at_most_once_per_axis_per_layout, a measured leaf ten containers deep in a shrinking row, accepted up to two probes. It now expects one, and sees 2 without this change.

yarn gentest -h leaves the tree clean, and node ./scripts/clang-format.js --check passes.

Changelog:
[General][Changed] - Yoga calls a measure function for an automatic minimum size only on the axis it needs

  • Simplify alongMainAxis check and assert probed axis in test

Reviewed By: javache

Differential Revision: D135328393

javache and others added 2 commits December 2, 2026 06:17
…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
…t#2102)

Summary:
* Walk only the requested axis for a container's min-content size

Why
===
The min-content walk behind automatic minimum sizes (css-flexbox-1 §4.5) is asked for a container's size on one axis. For every child it computed the size on both of the container's axes, summed one, took the largest of the other, and returned only the one it was asked for. The work on the other axis was wasted: a leaf was measured, and a container walked, on an axis no flex line needed.

How
===
The walk asks each child for the requested axis alone. It sums the children where that is the container's main axis and takes the largest where it is the cross axis. Layout results are unchanged. The memo already kept a leaf to one probe per axis per layout, so the saving is one measure call per leaf, and one walk per container, on the axis nobody asked for.

Test Plan
=========
`cmake --build tests/build && tests/build/yogatests` passes. `nested_leaf_probed_at_most_once_per_axis_per_layout`, a measured leaf ten containers deep in a shrinking row, accepted up to two probes. It now expects one, and sees 2 without this change.

`yarn gentest -h` leaves the tree clean, and `node ./scripts/clang-format.js --check` passes.

Changelog:
[General][Changed] - Yoga calls a measure function for an automatic minimum size only on the axis it needs

* Simplify alongMainAxis check and assert probed axis in test

---------

Reviewed By: javache

Differential Revision: D135328393
@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 D135328393.

This branch has not been deployed

No deployments
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. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant