From a561df0e96da334a44e4e8b798c1be9e19fa1bc2 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Mon, 1 Aug 2022 13:57:36 -0700 Subject: [PATCH] Exit early if currentShadowNode cannot be casted Summary: This diff fixes the bug T127619309 by exit early during calculateTransformedFrames if currentShadowNode cannot be casted This is a bug that fired in fb4a but we didn't have a way to reproduce locally. We are going to release this and enable feature flag with a MC changelog: [internal] internal Reviewed By: sammy-SC Differential Revision: D38280674 fbshipit-source-id: 1c42c17678d8473564e4075a78d3c688efed1a23 --- .../react/renderer/core/LayoutableShadowNode.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ReactCommon/react/renderer/core/LayoutableShadowNode.cpp b/ReactCommon/react/renderer/core/LayoutableShadowNode.cpp index 7f3c1f0382a..8861c82f556 100644 --- a/ReactCommon/react/renderer/core/LayoutableShadowNode.cpp +++ b/ReactCommon/react/renderer/core/LayoutableShadowNode.cpp @@ -30,6 +30,11 @@ static LayoutableSmallVector calculateTransformedFrames( for (int i = size - 1; i >= 0; --i) { auto currentShadowNode = traitCast(shadowNodeList.at(i)); + + if (!currentShadowNode) { + return {}; + } + auto currentFrame = currentShadowNode->getLayoutMetrics().frame; if (policy.includeTransform) { @@ -166,6 +171,11 @@ LayoutMetrics LayoutableShadowNode::computeRelativeLayoutMetrics( auto transformedFrames = shouldCalculateTransformedFrames ? calculateTransformedFrames(shadowNodeList, policy) : LayoutableSmallVector(); + + if (transformedFrames.empty()) { + return EmptyLayoutMetrics; + } + auto layoutMetrics = descendantLayoutableNode->getLayoutMetrics(); auto &resultFrame = layoutMetrics.frame; resultFrame.origin = {0, 0};