Repository navigation
Shrink the items of a fit-content row that is wider than its space (#2143) - #60549
Merged
Merged
Conversation
|
@javache has exported this pull request. If you are a Meta employee, you can view the originating Diff in D135547835. |
…eact#2143) Differential Revision: https://www.internalfb.com/diff/D135547835 Summary: Why === A row that is not stretched, such as a row in a column with `align-items: flex-start`, is sized to fit its content. CSS makes it as wide as the space available when its content is wider than that, but no narrower than its min-content width, and then flexes its items in that width (the fit-content size, css-sizing-3 §2.1; css-flexbox-1 §9.2). Without the `StretchFlexBasis` erratum, Yoga keeps such a row at its max-content width and never shrinks its items: ```html <div style="width: 100px; align-items: flex-start"> <div style="flex-direction: row"> <div style="flex-shrink: 1">aaaa bbbb cccc</div> <div style="width: 40px; height: 10px"></div> </div> </div> ``` Chrome makes the row 100 wide and wraps the text in the 60 left of it. Yoga makes the row 140 wide, with the text 100 wide beside the box. How === When a row's main size is `FitContent` and a line is wider than the space available, `calculateLayoutImpl` now gives the row that space, or the row's min-content width if that is larger, and leaves the difference as negative free space for the items to shrink into. The min-content width is `computeMinContentMainSize`, which the automatic minimum size already uses, so the row stops shrinking where its items' stated sizes and unbreakable content add up: two `width: 80px` items keep a row 160 wide in a 100-wide column, as in Chrome, with or without automatic minimum sizes. A column is unchanged: Chrome keeps a column at its content's height, and Yoga already does. The old behavior becomes the erratum `FitContentRowKeepsMaxContentWidth`, set on new configs and included in `YGErrataAll` and `YGErrataClassic`, as `MinSizeUndefinedInsteadOfAuto` and `FlexFirstPassUsesRunningTotals` are: clearing an erratum promises conformance, and a default config lays out as before. The configuring page names it in a sentence of its own, apart from the sentence that lists the other default errata, so that this change and other changes to that list do not conflict. With `StretchFlexBasis` set, Yoga already shrinks these items, to the space available and no further, and this change leaves that path alone. A row that is itself an item of a row needs one more change. Its flex base size is its max-content width (css-flexbox-1 §9.2, step 3E), but Yoga measures an item for its flex basis within the width available to the container, and a row that shrinks to fit would shrink in that measure. With the erratum cleared, `computeFlexBasisForChild` measures a row item of a row with no available width. This applies in every row, not only one sized to fit its content: in a 100-wide row, a nested row of wrapping text and a 40-wide box was 140 wide with the text wrapped, and is now 180 wide with the text on one line, as in Chrome (`fit_content_row_in_row_has_max_content_flex_basis`). The nested row shrinks if it has `flex-shrink`. The change stops at rows because only a row shrinks in that measure; a column or a text node is still measured within the width available, so that text wraps to it, which is the third limit below. Three limits remain with the erratum cleared: - A row whose items cannot shrink far enough is as wide as its items, where Chrome keeps it at the width available and lets the items overflow. A row sized to fit its content that holds the nested row above is 180 wide in Yoga and 100 in Chrome. - The min-content width does not floor an item that cannot shrink at its flex basis (css-flexbox-1 §9.9.3). For `flex-basis: 80px; flex-shrink: 1` text beside a `flex-basis: 80px` box, Chrome makes the row 120 wide and Yoga 100. - An item of a row that is not a row itself, such as a column or text, is still measured for its flex basis within the width available, so text in it wraps where Chrome keeps it on one line. This is Yoga's behavior with or without the erratum. Test Plan ========= `yarn gentest -f YGFitContentRowTest`, then `cmake --build tests/build && tests/build/yogatests` passes. The fixtures hold Chrome's layout with the errata cleared. With the erratum check forced on, which is the layout before this change, these fail: | Test | Chrome | Before | | --- | --- | --- | | `fit_content_row_shrinks_wrapping_text` | row 100 wide, text 60×30 | row 140, text 100×20 | | `fit_content_row_shrinks_without_automatic_minimum_sizes` | root height 30 | 20 | | `fit_content_row_shrinks_inside_padding_and_gap` | root height 40 | 30 | | `fit_content_row_stops_at_min_content_width` | row 120 wide, 50 high | 140, 40 | | `fit_content_scroll_row_shrinks_wrapping_text` | root height 30 | 10 | | `fit_content_row_in_row_has_max_content_flex_basis` | nested row 180 wide | 140 | `fit_content_row_keeps_stated_widths` and `fit_content_column_keeps_content_height` pass before and after: the first fails if the row shrinks past its min-content width, and the second if a column shrinks. `fit_content_row_stops_at_min_content_width` also fails if the row's padding is counted twice. The hand-written `fit_content_row_shrinks_only_without_errata` checks that a new config has the erratum and keeps the old layout, that clearing it shrinks the row, and that `YGErrataClassic`, which includes it, keeps the old layout. `yarn format-check` and `yarn lint` pass. The Java and JavaScript suites were generated but not run: this machine has no Emscripten or Gradle. Changelog: [General][Added] - Add the `FitContentRowKeepsMaxContentWidth` erratum; clearing it lets a row that is sized to fit its content shrink its items when the content is wider than the space available, and gives a row that is an item of a row its max-content width as its flex base size
javache
force-pushed
the
export-D135547835
branch
2 times, most recently
from
December 4, 2026 20:25
8e84e4d to
7cad85f
Compare
Abbondanzo
approved these changes
Dec 4, 2026
Abbondanzo
left a comment
Contributor
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
javache
force-pushed
the
export-D135547835
branch
from
December 4, 2026 20:29
7cad85f to
fb397a5
Compare
Collaborator
|
This pull request was successfully merged by @javache in 018bd47 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.
Differential Revision: https://www.internalfb.com/diff/D135547835
Summary:
Why
A row that is not stretched, such as a row in a column with
align-items: flex-start, is sized to fit its content. CSS makes it as wide as the space available when its content is wider than that, but no narrower than its min-content width, and then flexes its items in that width (the fit-content size, css-sizing-3 §2.1; css-flexbox-1 §9.2). Without theStretchFlexBasiserratum, Yoga keeps such a row at its max-content width and never shrinks its items:Chrome makes the row 100 wide and wraps the text in the 60 left of it. Yoga makes the row 140 wide, with the text 100 wide beside the box.
How
When a row's main size is
FitContentand a line is wider than the space available,calculateLayoutImplnow gives the row that space, or the row's min-content width if that is larger, and leaves the difference as negative free space for the items to shrink into. The min-content width iscomputeMinContentMainSize, which the automatic minimum size already uses, so the row stops shrinking where its items' stated sizes and unbreakable content add up: twowidth: 80pxitems keep a row 160 wide in a 100-wide column, as in Chrome, with or without automatic minimum sizes. A column is unchanged: Chrome keeps a column at its content's height, and Yoga already does.The old behavior becomes the erratum
FitContentRowKeepsMaxContentWidth, set on new configs and included inYGErrataAllandYGErrataClassic, asMinSizeUndefinedInsteadOfAutoandFlexFirstPassUsesRunningTotalsare: clearing an erratum promises conformance, and a default config lays out as before. The configuring page names it in a sentence of its own, apart from the sentence that lists the other default errata, so that this change and other changes to that list do not conflict. WithStretchFlexBasisset, Yoga already shrinks these items, to the space available and no further, and this change leaves that path alone.A row that is itself an item of a row needs one more change. Its flex base size is its max-content width (css-flexbox-1 §9.2, step 3E), but Yoga measures an item for its flex basis within the width available to the container, and a row that shrinks to fit would shrink in that measure. With the erratum cleared,
computeFlexBasisForChildmeasures a row item of a row with no available width. This applies in every row, not only one sized to fit its content: in a 100-wide row, a nested row of wrapping text and a 40-wide box was 140 wide with the text wrapped, and is now 180 wide with the text on one line, as in Chrome (fit_content_row_in_row_has_max_content_flex_basis). The nested row shrinks if it hasflex-shrink. The change stops at rows because only a row shrinks in that measure; a column or a text node is still measured within the width available, so that text wraps to it, which is the third limit below.Three limits remain with the erratum cleared:
flex-basis: 80px; flex-shrink: 1text beside aflex-basis: 80pxbox, Chrome makes the row 120 wide and Yoga 100.Test Plan
yarn gentest -f YGFitContentRowTest, thencmake --build tests/build && tests/build/yogatestspasses. The fixtures hold Chrome's layout with the errata cleared. With the erratum check forced on, which is the layout before this change, these fail:fit_content_row_shrinks_wrapping_textfit_content_row_shrinks_without_automatic_minimum_sizesfit_content_row_shrinks_inside_padding_and_gapfit_content_row_stops_at_min_content_widthfit_content_scroll_row_shrinks_wrapping_textfit_content_row_in_row_has_max_content_flex_basisfit_content_row_keeps_stated_widthsandfit_content_column_keeps_content_heightpass before and after: the first fails if the row shrinks past its min-content width, and the second if a column shrinks.fit_content_row_stops_at_min_content_widthalso fails if the row's padding is counted twice. The hand-writtenfit_content_row_shrinks_only_without_erratachecks that a new config has the erratum and keeps the old layout, that clearing it shrinks the row, and thatYGErrataClassic, which includes it, keeps the old layout.yarn format-checkandyarn lintpass. The Java and JavaScript suites were generated but not run: this machine has no Emscripten or Gradle.Changelog:
[General][Added] - Add the
FitContentRowKeepsMaxContentWidtherratum; clearing it lets a row that is sized to fit its content shrink its items when the content is wider than the space available, and gives a row that is an item of a row its max-content width as its flex base size