Repository navigation
Keep a display: none child zeroed out in a wrap-reverse container (#2137) - #60544
Merged
Merged
Conversation
…react#2137) Summary: Why === A `wrap-reverse` container ends its layout by mirroring each child's cross-axis position, computed from the child's measured size. A `display: none` child has no measured size, so its position becomes NaN where a browser reports 0: ```html <div style="width: 100px; height: 100px; flex-direction: row; flex-wrap: wrap-reverse"> <div style="width: 20px; height: 20px"></div> <div style="width: 20px; height: 20px; display: none"> <div style="width: 10px; height: 10px"></div> </div> </div> ``` Pixel-grid rounding then derives each size from the absolute position, so the hidden child and its descendants also get a NaN height (a NaN width in a column container). A hidden subtree with NaN in its layout never counts as zeroed out, with or without rounding, so `zeroOutLayoutRecursively` clones all of it on every layout of the container, which is the work react#2055 and react#2058 removed for other containers. How === The loop that mirrors positions skips `display: none` children, as the loop that sets trailing positions after it does. No erratum gates this: the old values are NaN, which no layout can depend on. Test Plan ========= `yarn gentest -f YGDisplayTest` adds `display_none_in_wrap_reverse` from the markup above, with Chrome's values. `cmake --build tests/build && tests/build/yogatests` passes. With `yoga/algorithm/CalculateLayout.cpp` reverted, the new test fails: the hidden child's top is NaN where Chrome has 0, and its height and its child's height are NaN. `relayout_does_not_clone_zeroed_out_display_none_subtree_in_wrap_reverse` in `YGPersistentNodeCloningTest.cpp` checks the cloning: a relayout clones the hidden child, which the two trees share, and not its child. On `main` it clones both. `yarn format-check` and `yarn lint` pass. Not run: the generated Java and JavaScript tests. Changelog: [General][Fixed] - Fix Yoga giving a `display: none` child of a `wrap-reverse` container a NaN position and size Reviewed By: javache Differential Revision: D135511404
|
@javache has exported this pull request. If you are a Meta employee, you can view the originating Diff in D135511404. |
Visual regressionNo visual differences at ios: no capture |
meta-codesync Bot
pushed a commit
to meta/litho
that referenced
this pull request
Dec 4, 2026
… (#2137) Summary: X-link: react/react-native#60544 Why === A `wrap-reverse` container ends its layout by mirroring each child's cross-axis position, computed from the child's measured size. A `display: none` child has no measured size, so its position becomes NaN where a browser reports 0: ```html <div style="width: 100px; height: 100px; flex-direction: row; flex-wrap: wrap-reverse"> <div style="width: 20px; height: 20px"></div> <div style="width: 20px; height: 20px; display: none"> <div style="width: 10px; height: 10px"></div> </div> </div> ``` Pixel-grid rounding then derives each size from the absolute position, so the hidden child and its descendants also get a NaN height (a NaN width in a column container). A hidden subtree with NaN in its layout never counts as zeroed out, with or without rounding, so `zeroOutLayoutRecursively` clones all of it on every layout of the container, which is the work #2055 and #2058 removed for other containers. How === The loop that mirrors positions skips `display: none` children, as the loop that sets trailing positions after it does. No erratum gates this: the old values are NaN, which no layout can depend on. Test Plan ========= `yarn gentest -f YGDisplayTest` adds `display_none_in_wrap_reverse` from the markup above, with Chrome's values. `cmake --build tests/build && tests/build/yogatests` passes. With `yoga/algorithm/CalculateLayout.cpp` reverted, the new test fails: the hidden child's top is NaN where Chrome has 0, and its height and its child's height are NaN. `relayout_does_not_clone_zeroed_out_display_none_subtree_in_wrap_reverse` in `YGPersistentNodeCloningTest.cpp` checks the cloning: a relayout clones the hidden child, which the two trees share, and not its child. On `main` it clones both. `yarn format-check` and `yarn lint` pass. Not run: the generated Java and JavaScript tests. Changelog: [General][Fixed] - Fix Yoga giving a `display: none` child of a `wrap-reverse` container a NaN position and size Reviewed By: javache Differential Revision: D135511404 fbshipit-source-id: 4d79cd2fd43d3db10d2a2c10bfaaa5cbd1895c1d
Collaborator
|
This pull request was successfully merged by @javache in 8dd1539 When will my fix make it into a release? | How to file a pick request? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Why
A
wrap-reversecontainer ends its layout by mirroring each child's cross-axis position, computed from the child's measured size. Adisplay: nonechild has no measured size, so its position becomes NaN where a browser reports 0:Pixel-grid rounding then derives each size from the absolute position, so the hidden child and its descendants also get a NaN height (a NaN width in a column container). A hidden subtree with NaN in its layout never counts as zeroed out, with or without rounding, so
zeroOutLayoutRecursivelyclones all of it on every layout of the container, which is the work #2055 and #2058 removed for other containers.How
The loop that mirrors positions skips
display: nonechildren, as the loop that sets trailing positions after it does. No erratum gates this: the old values are NaN, which no layout can depend on.Test Plan
yarn gentest -f YGDisplayTestaddsdisplay_none_in_wrap_reversefrom the markup above, with Chrome's values.cmake --build tests/build && tests/build/yogatestspasses. Withyoga/algorithm/CalculateLayout.cppreverted, the new test fails: the hidden child's top is NaN where Chrome has 0, and its height and its child's height are NaN.relayout_does_not_clone_zeroed_out_display_none_subtree_in_wrap_reverseinYGPersistentNodeCloningTest.cppchecks the cloning: a relayout clones the hidden child, which the two trees share, and not its child. Onmainit clones both.yarn format-checkandyarn lintpass. Not run: the generated Java and JavaScript tests.Changelog:
[General][Fixed] - Fix Yoga giving a
display: nonechild of awrap-reversecontainer a NaN position and sizeReviewed By: javache
Differential Revision: D135511404