diff --git a/packages/react-native/ReactCommon/yoga/yoga/YGNodeStyle.cpp b/packages/react-native/ReactCommon/yoga/yoga/YGNodeStyle.cpp index e43a38e64eb8..86da8ddf2004 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/YGNodeStyle.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/YGNodeStyle.cpp @@ -152,7 +152,16 @@ YGOverflow YGNodeStyleGetOverflow(const YGNodeConstRef node) { } void YGNodeStyleSetDisplay(const YGNodeRef node, const YGDisplay display) { + const bool wasContents = + resolveRef(node)->style().display() == Display::Contents; updateStyle<&Style::display, &Style::setDisplay>(node, scopedEnum(display)); + + // The owner caches how many of its children use display: contents, so it + // has to be recomputed when an attached child switches to or from it. + auto owner = resolveRef(node)->getOwner(); + if (owner != nullptr && wasContents != (display == YGDisplayContents)) { + owner->setChildren(owner->getChildren()); + } } YGDisplay YGNodeStyleGetDisplay(const YGNodeConstRef node) {