Skip to content

Fix style keywords reading back as the wrong unit after a non-integer size (#2056) (#59745) - #59745

Open
javache wants to merge 1 commit into
react:mainfrom
javache:export-D128898045
Open

javache wants to merge 1 commit into
react:mainfrom
javache:export-D128898045

Conversation

@javache

@javache javache commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

Summary

Fixes #2052.

Replacing a non-integer size with max-content, fit-content, or stretch could make the getter return a different keyword. YGNodeStyleSetHeight(node, 0.5f), then YGNodeStyleSetWidth(node, 0.25f), then YGNodeStyleSetWidthMaxContent(node) made YGNodeStyleGetWidth return YGUnitFitContent instead of YGUnitMaxContent.

A non-integer size is stored in the value pool, and the handle keeps that pool index in its value bits. storeKeyword changed the type to Keyword but left the indexed bit set, so isKeyword compared the pool index with the keyword enum (MaxContent = 0, FitContent = 1, Stretch = 2). The same mismatch affects height, min and max size, and flex-basis. A pool index of 3 or more matches no keyword and hits the debug assert in getSize.

auto, undefined, margin, and padding read the type bits only, so those getters were already correct. storeKeyword still writes the keyword into the handle's existing pool slot. getSize now reads that slot when the indexed bit is set, so the handle keeps the slot and the getter returns the stored keyword.

Test plan

  • YogaTest.width_keyword_replaces_pooled_number covers the [ScrollView] Why the top of ScrollView has more than 20 pixels #2052 sequence.
  • StyleValuePool.store_keywords_after_large_int checks max-content, fit-content, and stretch in pool slots 0 through 3.
  • StyleValuePool.store_large_int_and_keyword_repeatedly switches a pooled number and max-content 5000 times and checks that the slot is reused.
  • ./unit_tests Debug: 880 passed, 0 failed. Baseline before these tests was 877 passed, 0 failed.

Changelog:
[General][Fixed] - Fix reading back max-content, fit-content, and stretch after a non-integer size was stored

Reviewed By: javache

Differential Revision: D128898045

@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 Nov 2, 2026
@meta-codesync

meta-codesync Bot commented Nov 2, 2026

Copy link
Copy Markdown

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

@facebook-github-tools facebook-github-tools Bot added p: Facebook Partner: Facebook Partner labels Nov 2, 2026
javache pushed a commit to javache/react-native that referenced this pull request Nov 2, 2026
… size (react#2056) (react#59745)

Summary:
Pull Request resolved: react#59745

## Summary

Fixes react#2052.

Replacing a non-integer size with `max-content`, `fit-content`, or `stretch` could make the getter return a different keyword. `YGNodeStyleSetHeight(node, 0.5f)`, then `YGNodeStyleSetWidth(node, 0.25f)`, then `YGNodeStyleSetWidthMaxContent(node)` made `YGNodeStyleGetWidth` return `YGUnitFitContent` instead of `YGUnitMaxContent`.

A non-integer size is stored in the value pool, and the handle keeps that pool index in its value bits. `storeKeyword` changed the type to `Keyword` but left the indexed bit set, so `isKeyword` compared the pool index with the keyword enum (`MaxContent` = 0, `FitContent` = 1, `Stretch` = 2). The same mismatch affects height, min and max size, and flex-basis. A pool index of 3 or more matches no keyword and hits the debug assert in `getSize`.

`auto`, `undefined`, margin, and padding read the type bits only, so those getters were already correct. `storeKeyword` still writes the keyword into the handle's existing pool slot. `getSize` now reads that slot when the indexed bit is set, so the handle keeps the slot and the getter returns the stored keyword.

## Test plan

- `YogaTest.width_keyword_replaces_pooled_number` covers the react#2052 sequence.
- `StyleValuePool.store_keywords_after_large_int` checks max-content, fit-content, and stretch in pool slots 0 through 3.
- `StyleValuePool.store_large_int_and_keyword_repeatedly` switches a pooled number and max-content 5000 times and checks that the slot is reused.
- `./unit_tests Debug`: 880 passed, 0 failed. Baseline before these tests was 877 passed, 0 failed.

Changelog:
[General][Fixed] - Fix reading back max-content, fit-content, and stretch after a non-integer size was stored

Reviewed By: javache

Differential Revision: D128898045
@meta-codesync meta-codesync Bot changed the title Fix style keywords reading back as the wrong unit after a non-integer size (#2056) Fix style keywords reading back as the wrong unit after a non-integer size (#2056) (#59745) Nov 2, 2026
meta-codesync Bot pushed a commit to meta/litho that referenced this pull request Nov 2, 2026
… size (#2056)

Summary:
X-link: react/react-native#59745

## Summary

Fixes #2052.

Replacing a non-integer size with `max-content`, `fit-content`, or `stretch` could make the getter return a different keyword. `YGNodeStyleSetHeight(node, 0.5f)`, then `YGNodeStyleSetWidth(node, 0.25f)`, then `YGNodeStyleSetWidthMaxContent(node)` made `YGNodeStyleGetWidth` return `YGUnitFitContent` instead of `YGUnitMaxContent`.

A non-integer size is stored in the value pool, and the handle keeps that pool index in its value bits. `storeKeyword` changed the type to `Keyword` but left the indexed bit set, so `isKeyword` compared the pool index with the keyword enum (`MaxContent` = 0, `FitContent` = 1, `Stretch` = 2). The same mismatch affects height, min and max size, and flex-basis. A pool index of 3 or more matches no keyword and hits the debug assert in `getSize`.

`auto`, `undefined`, margin, and padding read the type bits only, so those getters were already correct. `storeKeyword` still writes the keyword into the handle's existing pool slot. `getSize` now reads that slot when the indexed bit is set, so the handle keeps the slot and the getter returns the stored keyword.

## Test plan

- `YogaTest.width_keyword_replaces_pooled_number` covers the #2052 sequence.
- `StyleValuePool.store_keywords_after_large_int` checks max-content, fit-content, and stretch in pool slots 0 through 3.
- `StyleValuePool.store_large_int_and_keyword_repeatedly` switches a pooled number and max-content 5000 times and checks that the slot is reused.
- `./unit_tests Debug`: 880 passed, 0 failed. Baseline before these tests was 877 passed, 0 failed.

Changelog:
[General][Fixed] - Fix reading back max-content, fit-content, and stretch after a non-integer size was stored

Reviewed By: javache

Differential Revision: D128898045

fbshipit-source-id: 0c09558d2774b3ad58b34459466a2455811e18b4
@javache
javache enabled auto-merge (squash) November 2, 2026 21:58
… size (react#2056) (react#59745)

Summary:

## Summary

Fixes react#2052.

Replacing a non-integer size with `max-content`, `fit-content`, or `stretch` could make the getter return a different keyword. `YGNodeStyleSetHeight(node, 0.5f)`, then `YGNodeStyleSetWidth(node, 0.25f)`, then `YGNodeStyleSetWidthMaxContent(node)` made `YGNodeStyleGetWidth` return `YGUnitFitContent` instead of `YGUnitMaxContent`.

A non-integer size is stored in the value pool, and the handle keeps that pool index in its value bits. `storeKeyword` changed the type to `Keyword` but left the indexed bit set, so `isKeyword` compared the pool index with the keyword enum (`MaxContent` = 0, `FitContent` = 1, `Stretch` = 2). The same mismatch affects height, min and max size, and flex-basis. A pool index of 3 or more matches no keyword and hits the debug assert in `getSize`.

`auto`, `undefined`, margin, and padding read the type bits only, so those getters were already correct. `storeKeyword` still writes the keyword into the handle's existing pool slot. `getSize` now reads that slot when the indexed bit is set, so the handle keeps the slot and the getter returns the stored keyword.

## Test plan

- `YogaTest.width_keyword_replaces_pooled_number` covers the react#2052 sequence.
- `StyleValuePool.store_keywords_after_large_int` checks max-content, fit-content, and stretch in pool slots 0 through 3.
- `StyleValuePool.store_large_int_and_keyword_repeatedly` switches a pooled number and max-content 5000 times and checks that the slot is reused.
- `./unit_tests Debug`: 880 passed, 0 failed. Baseline before these tests was 877 passed, 0 failed.

Changelog:
[General][Fixed] - Fix reading back max-content, fit-content, and stretch after a non-integer size was stored

Reviewed By: javache

Differential Revision: D128898045

This branch has not been deployed

No deployments
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. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ScrollView] Why the top of ScrollView has more than 20 pixels

2 participants