From 8dc2fa52c1d59ed875f6ada82a70c078c5e48855 Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Fri, 25 Oct 2024 17:34:36 -0700 Subject: [PATCH] Fix for nodes with `display: contents` not being cleaned in some cases (#1729) Summary: X-link: https://github.com/facebook/react-native/pull/47194 Fixes a case where a node with `display: contents` would not be cleaned up in some cases. This was caused by it being called after some early returns handling different quick paths. This PR moves the call to `cleanupContentsNodesRecursively` earlier so that it's always called. The problem here wasn't mutating before cloning, but leaving a node marked as dirty after the layout has finished. The exact case in which I found this was a node with a single `display: contents` child which needs to be a leaf. Then in the parent node [this](https://github.com/facebook/yoga/blob/b0b842d5e75d041e3af7e0ac55abfb8929fbbf21/yoga/algorithm/CalculateLayout.cpp#L1339) condition is true, so `cleanupContentsNodesRecursively` doesn't get called and the child node is never visited and cleaned. I assume the same will happen in the other paths with an early return here. Changelog: [General][Fixed] - Fix for nodes with `display: contents` not being cleaned in some cases Pull Request resolved: https://github.com/facebook/yoga/pull/1729 Reviewed By: rozele Differential Revision: D64910099 Pulled By: NickGerleman fbshipit-source-id: 6d56f8fbf687b7ee5af889c0b868406213c9cee8 --- yoga/algorithm/CalculateLayout.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/yoga/algorithm/CalculateLayout.cpp b/yoga/algorithm/CalculateLayout.cpp index 40a37bc754..1932ff5508 100644 --- a/yoga/algorithm/CalculateLayout.cpp +++ b/yoga/algorithm/CalculateLayout.cpp @@ -1316,6 +1316,10 @@ static void calculateLayoutImpl( flexColumnDirection, direction, ownerWidth), PhysicalEdge::Bottom); + // Clean and update all display: contents nodes with a direct path to the + // current node as they will not be traversed + cleanupContentsNodesRecursively(node); + if (node->hasMeasureFunc()) { measureNodeWithMeasureFunc( node, @@ -1366,9 +1370,6 @@ static void calculateLayoutImpl( // Reset layout flags, as they could have changed. node->setLayoutHadOverflow(false); - // Clean and update all display: contents nodes with a direct path to the - // current node as they will not be traversed - cleanupContentsNodesRecursively(node); // STEP 1: CALCULATE VALUES FOR REMAINDER OF ALGORITHM const FlexDirection mainAxis = resolveDirection(node->style().flexDirection(), direction);