Skip to content

guard shrink-factor division against floating-point near-zero (#57175) - #57175

Closed
cipolleschi wants to merge 1 commit into
react:mainfrom
cipolleschi:export-D108030908
Closed

guard shrink-factor division against floating-point near-zero (#57175)#57175
cipolleschi wants to merge 1 commit into
react:mainfrom
cipolleschi:export-D108030908

Conversation

@cipolleschi

@cipolleschi cipolleschi commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Summary:

fixes react/yoga#1665.

problem: when all flex children are frozen to their min-width in the first
pass, totalFlexShrinkScaledFactors is reduced to near-zero by floating-point
cancellation rather than exactly 0. the guard in distributeFreeSpaceSecondPass
uses exact equality (== 0), so it never fires, and the second pass divides
remainingFreeSpace by a value on the order of 1e-7, producing a childSize on
the order of 1e11 that overwhelms the min/max clamp.

fix: replace the exact-zero check with a relative epsilon guard
(shrinkFactorMagnitude < 1e-6f). when the magnitude is that small, all items
were already frozen in the first pass; the safe fallback (childFlexBasis + flexShrinkScaledFactor) applies and the subsequent boundAxisWithAutoMin clamps
correctly to minWidth.

regression: YGFlexShrinkBorderBug.flex_basis_0_border_minwidth_row reproduces
the original crash — 4 children, borderWidth difference of 1e-6 across them,
all now compute to their correct minWidth.

Changelog:

[Internal] -

X-link: react/yoga#1974

Reviewed By: javache

Differential Revision: D108030908

Pulled By: cipolleschi

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 11, 2026
@meta-codesync

meta-codesync Bot commented Jun 11, 2026

Copy link
Copy Markdown

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

@meta-codesync meta-codesync Bot changed the title guard shrink-factor division against floating-point near-zero guard shrink-factor division against floating-point near-zero (#57175) Aug 11, 2026
cipolleschi pushed a commit to cipolleschi/react-native that referenced this pull request Aug 11, 2026
…57175)

Summary:

fixes react/yoga#1665.

**problem:** when all flex children are frozen to their min-width in the first
pass, `totalFlexShrinkScaledFactors` is reduced to near-zero by floating-point
cancellation rather than exactly 0. the guard in `distributeFreeSpaceSecondPass`
uses exact equality (`== 0`), so it never fires, and the second pass divides
`remainingFreeSpace` by a value on the order of 1e-7, producing a childSize on
the order of 1e11 that overwhelms the min/max clamp.

**fix:** replace the exact-zero check with a relative epsilon guard
(`shrinkFactorMagnitude < 1e-6f`). when the magnitude is that small, all items
were already frozen in the first pass; the safe fallback (`childFlexBasis +
flexShrinkScaledFactor`) applies and the subsequent `boundAxisWithAutoMin` clamps
correctly to minWidth.

regression: `YGFlexShrinkBorderBug.flex_basis_0_border_minwidth_row` reproduces
the original crash — 4 children, `borderWidth` difference of 1e-6 across them,
all now compute to their correct minWidth.

## Changelog:
[Internal] -

X-link: react/yoga#1974

Reviewed By: javache

Differential Revision: D108030908

Pulled By: cipolleschi
…57175)

Summary:

fixes react/yoga#1665.

**problem:** when all flex children are frozen to their min-width in the first
pass, `totalFlexShrinkScaledFactors` is reduced to near-zero by floating-point
cancellation rather than exactly 0. the guard in `distributeFreeSpaceSecondPass`
uses exact equality (`== 0`), so it never fires, and the second pass divides
`remainingFreeSpace` by a value on the order of 1e-7, producing a childSize on
the order of 1e11 that overwhelms the min/max clamp.

**fix:** replace the exact-zero check with a relative epsilon guard
(`shrinkFactorMagnitude < 1e-6f`). when the magnitude is that small, all items
were already frozen in the first pass; the safe fallback (`childFlexBasis +
flexShrinkScaledFactor`) applies and the subsequent `boundAxisWithAutoMin` clamps
correctly to minWidth.

regression: `YGFlexShrinkBorderBug.flex_basis_0_border_minwidth_row` reproduces
the original crash — 4 children, `borderWidth` difference of 1e-6 across them,
all now compute to their correct minWidth.

## Changelog:
[Internal] -

X-link: react/yoga#1974

Reviewed By: javache

Differential Revision: D108030908

Pulled By: cipolleschi
meta-codesync Bot pushed a commit to react/yoga that referenced this pull request Aug 11, 2026
Summary:
X-link: react/react-native#57175

fixes #1665.

**problem:** when all flex children are frozen to their min-width in the first
pass, `totalFlexShrinkScaledFactors` is reduced to near-zero by floating-point
cancellation rather than exactly 0. the guard in `distributeFreeSpaceSecondPass`
uses exact equality (`== 0`), so it never fires, and the second pass divides
`remainingFreeSpace` by a value on the order of 1e-7, producing a childSize on
the order of 1e11 that overwhelms the min/max clamp.

**fix:** replace the exact-zero check with a relative epsilon guard
(`shrinkFactorMagnitude < 1e-6f`). when the magnitude is that small, all items
were already frozen in the first pass; the safe fallback (`childFlexBasis +
flexShrinkScaledFactor`) applies and the subsequent `boundAxisWithAutoMin` clamps
correctly to minWidth.

regression: `YGFlexShrinkBorderBug.flex_basis_0_border_minwidth_row` reproduces
the original crash — 4 children, `borderWidth` difference of 1e-6 across them,
all now compute to their correct minWidth.

## Changelog:
[Internal] -

X-link: #1974

Reviewed By: javache

Differential Revision: D108030908

Pulled By: cipolleschi

fbshipit-source-id: 3e8d4ef6773bc31703a54005bf610b2432f22d2d
@meta-codesync meta-codesync Bot closed this in 3e962d3 Aug 11, 2026
@meta-codesync meta-codesync Bot added the Merged This PR has been merged. label Aug 11, 2026
@meta-codesync

meta-codesync Bot commented Aug 11, 2026

Copy link
Copy Markdown

@cipolleschi merged this pull request in 3e962d3.

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flexBasis+flexShrink+borderWidth result in an wrong value

2 participants