Repository navigation
Size a baseline-aligned line by its other items' own sizes (#2138) (#60545) - #60545
Merged
Merged
Conversation
|
@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>
javache
force-pushed
the
export-D135515833
branch
from
December 4, 2026 17:25
46a05f6 to
1532d65
Compare
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? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
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
justifyMainAxiscounts 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 YGAlignItemsTestadds three fixtures with Chrome's values, andcmake --build tests/build && tests/build/yogatestspasses. Withyoga/algorithm/CalculateLayout.cppreverted, two fail: inalign_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 inalign_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_itempasses 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-checkandyarn lintpass. 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