Skip to content

Size a baseline-aligned line by its other items' own sizes (#2138) (#60545) - #60545

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

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

Conversation

@javache

@javache javache commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

Why

A flex line holds its baseline-aligned items, placed on their shared baseline, and its other items, and its cross size is the larger of the two groups' extents (css-flexbox-1 §9.4, step 8). When a row has any baseline-aligned item, Yoga sizes each line as if every item were baseline-aligned: it adds the largest distance above a baseline to the largest distance below one, over all items.

<div style="width: 300px; flex-direction: row">
  <div style="width: 50px; height: 50px"></div>
  <div style="width: 50px; height: 20px; margin-bottom: 40px"></div>
  <div style="width: 50px; height: 10px; align-self: baseline"></div>
  <div style="width: 50px"></div>
</div>

Chrome makes the row 60 high, the second item's height and margin, and stretches the fourth item to 60. Yoga makes both 90: the first item's 50 above its bottom edge plus the second item's 40 margin below its own.

How

justifyMainAxis counts an item toward the line's ascent and descent only if it is baseline-aligned, and takes the line's cross size as the larger of that sum and the largest outer cross size among the other items. The pass that positions the items of a baseline or wrapping container already computes each line's height this way, so in a wrapping container the lines were already placed by the right heights while the container was sized by the wrong ones.

No erratum gates this, as none gated #2107, which changed the same sum for a hidden baseline item. Only a row whose container or items ask for baseline alignment changes, and only when an item that is not baseline-aligned sets the largest ascent or descent, through a margin or through content that puts its baseline above its bottom edge; its line shrinks to what the positioning pass already uses.

Test Plan

yarn gentest -f YGAlignItemsTest adds three fixtures with Chrome's values, and cmake --build tests/build && tests/build/yogatests passes. With yoga/algorithm/CalculateLayout.cpp reverted, two fail: in align_self_baseline_line_stretches_items_to_its_size (the markup above) the row and its stretched item are 90 high where Chrome has 60, and in align_self_baseline_multiline_fits_lines, a wrapping row of two lines, the row is 100 high where Chrome has 70. align_baseline_line_fits_taller_flex_end_item passes before and after: its tallest item is not baseline-aligned, and it fails (50 where Chrome has 70) if the line's size is taken from the baseline-aligned items alone.

yarn format-check and yarn lint pass. Not run: the generated Java and JavaScript tests.

Changelog:
[General][Fixed] - Fix Yoga making a row with a baseline-aligned item taller than its items when another item's content or margins extend past the shared baseline

Reviewed By: javache

Differential Revision: D135515833

Signed-off-by: GitHub Workflows Support generatedunixname499836121@meta.com

@meta-codesync

meta-codesync Bot commented Dec 4, 2026

Copy link
Copy Markdown

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

… (react#60545)

Summary:
Pull Request resolved: react#60545

Why
===

A flex line holds its baseline-aligned items, placed on their shared baseline, and its other items, and its cross size is the larger of the two groups' extents ([css-flexbox-1 §9.4, step 8](https://www.w3.org/TR/css-flexbox-1/#algo-cross-line)). When a row has any baseline-aligned item, Yoga sizes each line as if every item were baseline-aligned: it adds the largest distance above a baseline to the largest distance below one, over all items.

```html
<div style="width: 300px; flex-direction: row">
  <div style="width: 50px; height: 50px"></div>
  <div style="width: 50px; height: 20px; margin-bottom: 40px"></div>
  <div style="width: 50px; height: 10px; align-self: baseline"></div>
  <div style="width: 50px"></div>
</div>
```

Chrome makes the row 60 high, the second item's height and margin, and stretches the fourth item to 60. Yoga makes both 90: the first item's 50 above its bottom edge plus the second item's 40 margin below its own.

How
===

`justifyMainAxis` counts an item toward the line's ascent and descent only if it is baseline-aligned, and takes the line's cross size as the larger of that sum and the largest outer cross size among the other items. The pass that positions the items of a baseline or wrapping container already computes each line's height this way, so in a wrapping container the lines were already placed by the right heights while the container was sized by the wrong ones.

No erratum gates this, as none gated react#2107, which changed the same sum for a hidden baseline item. Only a row whose container or items ask for baseline alignment changes, and only when an item that is not baseline-aligned sets the largest ascent or descent, through a margin or through content that puts its baseline above its bottom edge; its line shrinks to what the positioning pass already uses.

Test Plan
=========

`yarn gentest -f YGAlignItemsTest` adds three fixtures with Chrome's values, and `cmake --build tests/build && tests/build/yogatests` passes. With `yoga/algorithm/CalculateLayout.cpp` reverted, two fail: in `align_self_baseline_line_stretches_items_to_its_size` (the markup above) the row and its stretched item are 90 high where Chrome has 60, and in `align_self_baseline_multiline_fits_lines`, a wrapping row of two lines, the row is 100 high where Chrome has 70. `align_baseline_line_fits_taller_flex_end_item` passes before and after: its tallest item is not baseline-aligned, and it fails (50 where Chrome has 70) if the line's size is taken from the baseline-aligned items alone.

`yarn format-check` and `yarn lint` pass. Not run: the generated Java and JavaScript tests.

Changelog:
[General][Fixed] - Fix Yoga making a row with a baseline-aligned item taller than its items when another item's content or margins extend past the shared baseline

Reviewed By: javache

Differential Revision: D135515833
Signed-off-by: GitHub Workflows Support <generatedunixname499836121@meta.com>
@meta-codesync meta-codesync Bot changed the title Size a baseline-aligned line by its other items' own sizes (#2138) Size a baseline-aligned line by its other items' own sizes (#2138) (#60545) Dec 4, 2026
@meta-codesync
meta-codesync Bot merged commit ab585e8 into react:main Dec 4, 2026
38 of 42 checks passed
@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @javache in ab585e8

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 4, 2026
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