Skip to content

Commit 40c7d8f

Browse files
sbuggaymeta-codesync[bot]
authored andcommitted
Fix Yoga Style equality crash for size-typed dimensions (#56429)
Summary: X-link: facebook/yoga#1931 Pull Request resolved: #56429 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==`. Reviewed By: joevilches Differential Revision: D100189121 fbshipit-source-id: 284f849d01ca7d15ca34d2dcaafaa92ee9dfd59f
1 parent 8550370 commit 40c7d8f

File tree

1 file changed

+28
-3
lines changed
  • packages/react-native/ReactCommon/yoga/yoga/style

1 file changed

+28
-3
lines changed

packages/react-native/ReactCommon/yoga/yoga/style/Style.h

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,10 +661,10 @@ class YG_EXPORT Style {
661661
lengthsEqual(padding_, pool_, other.padding_, other.pool_) &&
662662
lengthsEqual(border_, pool_, other.border_, other.pool_) &&
663663
lengthsEqual(gap_, pool_, other.gap_, other.pool_) &&
664-
lengthsEqual(dimensions_, pool_, other.dimensions_, other.pool_) &&
665-
lengthsEqual(
664+
sizeLengthsEqual(dimensions_, pool_, other.dimensions_, other.pool_) &&
665+
sizeLengthsEqual(
666666
minDimensions_, pool_, other.minDimensions_, other.pool_) &&
667-
lengthsEqual(
667+
sizeLengthsEqual(
668668
maxDimensions_, pool_, other.maxDimensions_, other.pool_) &&
669669
numbersEqual(aspectRatio_, pool_, other.aspectRatio_, other.pool_) &&
670670
gridTemplateColumns_ == other.gridTemplateColumns_ &&
@@ -716,6 +716,31 @@ class YG_EXPORT Style {
716716
});
717717
}
718718

719+
static inline bool sizeLengthsEqual(
720+
const StyleValueHandle& lhsHandle,
721+
const StyleValuePool& lhsPool,
722+
const StyleValueHandle& rhsHandle,
723+
const StyleValuePool& rhsPool) {
724+
return (lhsHandle.isUndefined() && rhsHandle.isUndefined()) ||
725+
(lhsPool.getSize(lhsHandle) == rhsPool.getSize(rhsHandle));
726+
}
727+
728+
template <size_t N>
729+
static inline bool sizeLengthsEqual(
730+
const std::array<StyleValueHandle, N>& lhs,
731+
const StyleValuePool& lhsPool,
732+
const std::array<StyleValueHandle, N>& rhs,
733+
const StyleValuePool& rhsPool) {
734+
return std::equal(
735+
lhs.begin(),
736+
lhs.end(),
737+
rhs.begin(),
738+
rhs.end(),
739+
[&](const auto& lhs, const auto& rhs) {
740+
return sizeLengthsEqual(lhs, lhsPool, rhs, rhsPool);
741+
});
742+
}
743+
719744
StyleValueHandle computeColumnGap() const {
720745
if (gap_[yoga::to_underlying(Gutter::Column)].isDefined()) {
721746
return gap_[yoga::to_underlying(Gutter::Column)];

0 commit comments

Comments
 (0)