diff --git a/packages/react-native/ReactCommon/yoga/yoga/node/Node.cpp b/packages/react-native/ReactCommon/yoga/yoga/node/Node.cpp index adb63663bed9b5..e2f03e2475720e 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/node/Node.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/node/Node.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -49,12 +50,29 @@ Node::Node(Node&& node) noexcept } YGSize Node::measure( - float width, + float availableWidth, MeasureMode widthMode, - float height, + float availableHeight, MeasureMode heightMode) { - return measureFunc_( - this, width, unscopedEnum(widthMode), height, unscopedEnum(heightMode)); + const auto size = measureFunc_( + this, + availableWidth, + unscopedEnum(widthMode), + availableHeight, + unscopedEnum(heightMode)); + + if (yoga::isUndefined(size.height) || size.height < 0 || + yoga::isUndefined(size.width) || size.width < 0) { + yoga::log( + this, + LogLevel::Error, + "Measure function returned an invalid dimension to Yoga: [width=%f, height=%f]", + size.width, + size.height); + return {.height = 0.0f, .width = 0.0f}; + } + + return size; } float Node::baseline(float width, float height) const { diff --git a/packages/react-native/ReactCommon/yoga/yoga/node/Node.h b/packages/react-native/ReactCommon/yoga/yoga/node/Node.h index 8f5ee591cc59e6..cd029b40d46671 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/node/Node.h +++ b/packages/react-native/ReactCommon/yoga/yoga/node/Node.h @@ -66,9 +66,9 @@ class YG_EXPORT Node : public ::YGNode { } YGSize measure( - float width, + float availableWidth, MeasureMode widthMode, - float height, + float availableHeight, MeasureMode heightMode); bool hasBaselineFunc() const noexcept {