Skip to content

Navigation Menu

Sign in
Sign up

guard shrink-factor division against floating-point near-zero - #1974

Open
harsha-cpp wants to merge 2 commits into
react:main from
harsha-cpp:fix/flex-grow-zero-divisor-1665
Open

guard shrink-factor division against floating-point near-zero #1974
harsha-cpp wants to merge 2 commits into
react:main from
harsha-cpp:fix/flex-grow-zero-divisor-1665

Conversation

@harsha-cpp

@harsha-cpp harsha-cpp commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

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.

vercel Bot commented Jun 9, 2026
edited
Loading

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
yoga-website Ready Ready Preview, Comment Jun 9, 2026 4:37pm

Request Review

@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 Jun 9, 2026

@cipolleschi cipolleschi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely spotted! Thanks for the fix

meta-codesync Bot commented Jun 9, 2026

Copy link
Copy Markdown

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this in D108030908.

Copy link
Copy Markdown
Contributor Author

thanks @cipolleschi

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
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
meta-codesync Bot pushed a commit 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 Bot pushed a commit to react/react-native that referenced this pull request Aug 11, 2026
Summary:
Pull Request resolved: #57175
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
fbshipit-source-id: 3e8d4ef6773bc31703a54005bf610b2432f22d2d
xesrevinu pushed a commit to opraying/react-native-macos that referenced this pull request Aug 30, 2026
...57175)
Summary:
Pull Request resolved: react#57175
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
fbshipit-source-id: 3e8d4ef6773bc31703a54005bf610b2432f22d2d
(cherry picked from commit 3e962d3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@cipolleschi cipolleschi cipolleschi approved these changes

Assignees

No one assigned

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

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

flexBasis+flexShrink+borderWidth result in an wrong value

AltStyle によって変換されたページ (->オリジナル) /