Skip to content

Commit f2f9209

Browse files
j-piaseckimeta-codesync[bot]
authored andcommitted
Fix node ownership when display: contents is used (#56422)
Summary: Pull Request resolved: #56422 Changelog: [GENERAL][FIXED] Fixed Yoga node ownership when `display: contents` is used in absolutely positioned subtrees Fixes an edge case where nodes with `display: contents` weren't cloned properly inside absolutely positioned subtrees. Adds a test case covering this scenario. X-link: react/yoga#1924 Reviewed By: NickGerleman Differential Revision: D100581579 Pulled By: j-piasecki fbshipit-source-id: e05e9a4076bd11a71be438ef910a262044659a9b
1 parent b111c0e commit f2f9209

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

packages/react-native/ReactCommon/yoga/yoga/algorithm/AbsoluteLayout.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ bool layoutAbsoluteDescendants(
558558
// we need to mutate these descendents. Make sure the path of
559559
// nodes to them is mutable before positioning.
560560
child->cloneChildrenIfNeeded();
561+
cleanupContentsNodesRecursively(child);
561562
const Direction childDirection =
562563
child->resolveDirection(currentNodeDirection);
563564
// By now all descendants of the containing block that are not absolute

packages/react-native/ReactCommon/yoga/yoga/node/Node.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,12 @@ void Node::cloneChildrenIfNeeded() {
392392
child = resolveRef(config_->cloneNode(child, this, i));
393393
child->setOwner(this);
394394

395-
if (child->hasContentsChildren()) [[unlikely]] {
395+
if (child->style().display() == Display::Contents) [[unlikely]] {
396+
// The contents node's children are treated as children of the
397+
// contents node's parent for layout purposes, so they need
398+
// to be cloned as well.
399+
child->cloneChildrenIfNeeded();
400+
} else if (child->hasContentsChildren()) [[unlikely]] {
396401
child->cloneContentsChildrenIfNeeded();
397402
}
398403
}

0 commit comments

Comments
 (0)