From 8e097ad88621253cb0e87a88e3b27ea815fba6b1 Mon Sep 17 00:00:00 2001 From: Devan Buggay Date: Mon, 13 Apr 2026 13:55:03 -0700 Subject: [PATCH] Fix Yoga Style equality crash for size-typed dimensions Summary: Changelog: [Internal] The existing `lengthsEqual` comparator was used for `dimensions_`, `minDimensions_`, and `maxDimensions_`, but these are size-typed values stored via `StyleValuePool::getSize()`, not length-typed. Using the wrong accessor caused crashes during style equality checks. Added a `sizeLengthsEqual` helper (scalar + array overloads) that correctly calls `StyleValuePool::getSize()` and swapped it in for the three dimension fields in `Style::operator==`. Differential Revision: D100189121 --- .../ReactCommon/yoga/yoga/style/Style.h | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/packages/react-native/ReactCommon/yoga/yoga/style/Style.h b/packages/react-native/ReactCommon/yoga/yoga/style/Style.h index 37c0ba2a9a8..a06bd246b45 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/style/Style.h +++ b/packages/react-native/ReactCommon/yoga/yoga/style/Style.h @@ -661,10 +661,10 @@ class YG_EXPORT Style { lengthsEqual(padding_, pool_, other.padding_, other.pool_) && lengthsEqual(border_, pool_, other.border_, other.pool_) && lengthsEqual(gap_, pool_, other.gap_, other.pool_) && - lengthsEqual(dimensions_, pool_, other.dimensions_, other.pool_) && - lengthsEqual( + sizeLengthsEqual(dimensions_, pool_, other.dimensions_, other.pool_) && + sizeLengthsEqual( minDimensions_, pool_, other.minDimensions_, other.pool_) && - lengthsEqual( + sizeLengthsEqual( maxDimensions_, pool_, other.maxDimensions_, other.pool_) && numbersEqual(aspectRatio_, pool_, other.aspectRatio_, other.pool_) && gridTemplateColumns_ == other.gridTemplateColumns_ && @@ -716,6 +716,31 @@ class YG_EXPORT Style { }); } + static inline bool sizeLengthsEqual( + const StyleValueHandle& lhsHandle, + const StyleValuePool& lhsPool, + const StyleValueHandle& rhsHandle, + const StyleValuePool& rhsPool) { + return (lhsHandle.isUndefined() && rhsHandle.isUndefined()) || + (lhsPool.getSize(lhsHandle) == rhsPool.getSize(rhsHandle)); + } + + template + static inline bool sizeLengthsEqual( + const std::array& lhs, + const StyleValuePool& lhsPool, + const std::array& rhs, + const StyleValuePool& rhsPool) { + return std::equal( + lhs.begin(), + lhs.end(), + rhs.begin(), + rhs.end(), + [&](const auto& lhs, const auto& rhs) { + return sizeLengthsEqual(lhs, lhsPool, rhs, rhsPool); + }); + } + StyleValueHandle computeColumnGap() const { if (gap_[yoga::to_underlying(Gutter::Column)].isDefined()) { return gap_[yoga::to_underlying(Gutter::Column)];