Skip to content

Add max-content support for width, height, and flex-basis - #2012

Open
intergalacticspacehighway wants to merge 1 commit into
react:mainfrom
intergalacticspacehighway:css-max-content-dimensions
Open

Add max-content support for width, height, and flex-basis#2012
intergalacticspacehighway wants to merge 1 commit into
react:mainfrom
intergalacticspacehighway:css-max-content-dimensions

Conversation

@intergalacticspacehighway

@intergalacticspacehighway intergalacticspacehighway commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Why

Implements the CSS max-content sizing keyword for width, height, and flex-basis.

The public setter (YGNodeStyleSetWidthMaxContent) already exist, but layout silently treated the keyword as auto. This PR makes them take effect.

We have a feature in Expo UI (RNHostView) that allows mounting a React Native hierarchy inside a SwiftUI hierarchy and allowing it to grow to it's natural size. So max-content would be very useful in that case (auto sizes are context dependent and often depend on parent dimensions)

How

The max-content allows content to be laid out to it's intrinsic size, given an indefinite space in an axis. It requires changes to root, flex-basis, cross-axis (prevent stretch) and absolute layout path.

Testing

Test includes browser generated max-content spec which aims to test all the control flow that is added in this PR and also some tests (specifying max-content to owner size) which is not supported by gentest yet.

TODOs

  • min-width: max-content, max-width: max-content not supported yet.
  • Aspect-ratio doesn't transfer from a resolved max-content axis yet (browsers do this). Documented in the disabled max_content_with_aspect_ratio fixture case and pinned by MaxContentAspectRatioTest. Currently aspect ratio needs some work to make it spec compliant, it has the same issue when child has percentage dimensions.

@meta-cla meta-cla Bot added the CLA Signed label Aug 27, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Aug 27, 2026
Implements the CSS max-content sizing keyword (css-sizing-3) for
dimensions and flex-basis. The public setters existed but layout
treated the keyword as auto; this makes them take effect.

Keyword axes are measured with indefinite available space, then laid
out at the measured (min/max clamped) size, so descendants resolve
percentages against the resolved value and wrap within it. Covers
root constraint minting (including a second height measure when a
width clamp changes wrapping), the flex-basis cascade, the cross-axis
path, the stretch re-layout guards, and absolute layout.

Aspect-ratio transfer from a resolved keyword axis is deferred; the
browser target is recorded in a disabled fixture case and the current
behavior is pinned by MaxContentAspectRatioTest. Root cases that need
a definite owner size are hand-written (gentest cannot express one).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant