From fa5974330f4bd437aa11bfe172f9122682900305 Mon Sep 17 00:00:00 2001 From: James Ide Date: Tue, 1 Dec 2026 17:15:00 -0800 Subject: [PATCH] Move the Yoga min-content clone test to a row `MinContentTest.testWalkClonesOnlyTheChildrenItWritesTo` lays out a column a second time at a narrower width and expects Yoga's min-content walk to clone one child of a shrinking item: the child with percentage padding, whose memo is keyed on the owner's width. The item states its width. Once Yoga always measures a min-content height at the width a box is given (react/yoga#2105, and react/yoga#2161, which removes the `MinContentHeightAtGivenWidth` experimental feature), the height walk resolves that padding against the item's width, which is the same in both trees, so it reads the child and clones nothing, and the test fails. The test now uses a row. A width walk still passes the container's width down and resolves the padding against it, so the padded child's memo is still keyed on a width that changes. A static min-content width of 100 on one leaf keeps the item 100 wide in both trees, so the item's layout comes from cache and only the walk can clone its children. The assertions are the same, with one more for the item's width. `BaselineTest.cpp`, built with GoogleTest against three copies of Yoga, passes: the vendored copy at this commit, Yoga's `main` at `d42a7a5c`, and that commit with the experimental feature removed (react/yoga#2161). Before this change the third fails at `EXPECT_NE(padded, YGNodeGetChild(itemCopy, 0))`. With `computeChildMinContentMainSize` changed to clone every child it visits, the test fails. --- .../ReactCommon/yoga/test/BaselineTest.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/react-native/ReactCommon/yoga/test/BaselineTest.cpp b/packages/react-native/ReactCommon/yoga/test/BaselineTest.cpp index be93bd6cfdeb..367db4e0986e 100644 --- a/packages/react-native/ReactCommon/yoga/test/BaselineTest.cpp +++ b/packages/react-native/ReactCommon/yoga/test/BaselineTest.cpp @@ -446,12 +446,11 @@ TEST(MinContentTest, testWalkClonesOnlyTheChildrenItWritesTo) { MeasureCalls paddedCalls; MeasureCalls stableCalls; YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root, YGAlignFlexStart); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); YGNodeStyleSetWidth(root, 300); YGNodeStyleSetHeight(root, 100); YGNodeRef item = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(item, 50); - YGNodeStyleSetHeight(item, 200); + YGNodeStyleSetFlexBasis(item, 100); YGNodeStyleSetFlexShrink(item, 1); YGNodeInsertChild(root, item, 0); YGNodeRef padded = YGNodeNewWithConfig(config); @@ -469,24 +468,28 @@ TEST(MinContentTest, testWalkClonesOnlyTheChildrenItWritesTo) { YGNodeInsertChild(item, absolute, 3); YGNodeRef staticLeaf = YGNodeNewWithConfig(config); YGNodeSetMeasureFunc(staticLeaf, measureUncounted); - YGNodeSetMinContentWidth(staticLeaf, 20); + YGNodeSetMinContentWidth(staticLeaf, 100); YGNodeSetMinContentHeight(staticLeaf, 5); YGNodeInsertChild(item, staticLeaf, 4); YGNodeRef empty = YGNodeNewWithConfig(config); YGNodeInsertChild(item, empty, 5); YGNodeRef sibling = YGNodeNewWithConfig(config); - YGNodeStyleSetHeight(sibling, 200); + YGNodeStyleSetFlexBasis(sibling, 300); YGNodeStyleSetFlexShrink(sibling, 1); YGNodeInsertChild(root, sibling, 1); YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - // Only `padded`'s memo is keyed on the width, so a narrower second tree walks - // it again and only reads the item's other children and `padded`'s leaf. + // The static leaf keeps the item 100 wide in a narrower second tree, so the + // item's layout comes from cache and only the walk reaches its children. + // The width walk resolves `padded`'s percentage against the root's width, so + // only its memo is keyed on that width: the walk walks it again and only + // reads the item's other children and `padded`'s leaf. YGNodeRef rootCopy = YGNodeClone(root); YGNodeStyleSetWidth(rootCopy, 290); YGNodeCalculateLayout(rootCopy, YGUndefined, YGUndefined, YGDirectionLTR); const YGNodeRef itemCopy = YGNodeGetChild(rootCopy, 0); + EXPECT_FLOAT_EQ(100.0f, YGNodeLayoutGetWidth(itemCopy)); EXPECT_NE(padded, YGNodeGetChild(itemCopy, 0)); EXPECT_EQ(paddedLeaf, YGNodeGetChild(YGNodeGetChild(itemCopy, 0), 0)); EXPECT_EQ(stable, YGNodeGetChild(itemCopy, 1));