From 96e5ec3d63154165167611e49683c0cc0e9884ff Mon Sep 17 00:00:00 2001 From: GitHub Workflows Support Date: Fri, 4 Dec 2026 01:44:06 -0800 Subject: [PATCH] Keep a `display: none` child zeroed out in a `wrap-reverse` container (#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
``` 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 --- .../ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp index 610dae1e370..398e5e9af6f 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp @@ -3000,7 +3000,10 @@ static void calculateLayoutImpl( // positions on wrap-reverse. if (performLayout && node->style().flexWrap() == Wrap::WrapReverse) { for (auto child : node->getLayoutChildren()) { - if (child->style().positionType() != PositionType::Absolute) { + // Skip hidden children because their measured size is NaN, and their + // position must stay zeroed out + if (child->style().display() != Display::None && + child->style().positionType() != PositionType::Absolute) { child->setLayoutPosition( node->getLayout().measuredDimension(dimension(crossAxis)) - child->getLayout().position(flexStartEdge(crossAxis)) -