Skip to content

Fix fixFlexBasisFitContent causing layout collapse on re-layout #1964

Open
scorsin-oai wants to merge 1 commit into
facebook:mainfrom
scorsin-oai:simon/260518-fix_flex_basis_fit_content
Open

Fix fixFlexBasisFitContent causing layout collapse on re-layout #1964
scorsin-oai wants to merge 1 commit into
facebook:mainfrom
scorsin-oai:simon/260518-fix_flex_basis_fit_content

Conversation

@scorsin-oai
Copy link
Copy Markdown

This change fixes an issue where nodes could collapse to 0 on re-layout when fixFlexBasisFitContent is enabled.

This is the setup:

<div id="zero_basis_column_wrapper_relayout"
     data-experiments="FixFlexBasisFitContent"
     style="width: 100px;">
  <div style="flex-basis: 0px; flex-grow: 0; flex-shrink: 0;">
    <div>x</div>
  </div>
</div>

Repro sequence:

YGNodeCalculateLayout(root, 100, YGUndefined, YGDirectionLTR);
// wrapper height is 10

YGNodeMarkDirty(text);
YGNodeCalculateLayout(root, 100, 20, YGDirectionLTR);
// Before fix: wrapper height flips to 0
// After fix: wrapper height stays 10

Yoga measured an auto-sized flex-basis: 0 item when the parent’s main-axis size was indefinite, so it got its intrinsic content size. On a later layout pass with a definite parent size, Yoga treated the resolved 0 basis as authoritative, skipped measurement, and collapsed the same item to 0.

What the fix does:

For FixFlexBasisFitContent, explicit flex-basis: 0 on an auto-sized, non-growing item stays on the measurement path, so its size is based on content consistently across layout passes. Flex-growing zero-basis items still use zero basis for normal flex distribution.

An explicit flex-basis: 0 on an auto-sized, non-growing item should not make Yoga skip intrinsic measurement. Before this change, computeFlexBasisForChild only ignored the resolved zero basis while the owner main-axis size was indefinite. If a later pass had a definite owner main-axis size, the same node started using the resolved zero flex basis, so its main size could flip from content-sized to zero without a style change.

That made layout depend on the shape of the previous layout pass. A measured label or a wrapper around measured content could be validly measured on the first pass, then collapse after the measured leaf was dirtied and the owner was laid out with a definite width or height. Runtime viewport and view-inflation layers can then treat visible descendants as outside a zero-sized ancestor.

When FixFlexBasisFitContent is enabled, make explicit zero flex-basis deterministic for auto-sized, non-growing items by keeping them on the measurement path in both row and column directions. This applies to measured leaves, wrapper containers, 0%, padded containers, nested wrappers, and web-default shrink. Growing flex items still use zero basis for normal flex distribution, and items with an explicit main-axis size continue to let flex-basis win.

Add focused tests for the original two-pass collapse in both axes and for related tree shapes that would otherwise hit the same root cause: direct measured children, first-definite layouts, percent zero basis, padding, nested wrappers, and web-default shrink. Add guardrails for flex-growing zero-basis items and explicit main-axis size behavior.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 18, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
yoga-website Ready Ready Preview, Comment May 18, 2026 3:43pm

Request Review

@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented May 18, 2026

Hi @scorsin-oai!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant