From f7a5db3c063b952321826ea431d3d238ef0de65d Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Wed, 8 Jan 2025 10:33:25 -0800 Subject: [PATCH] Fix TextMeasureCacheKey Throwing Out Some LayoutConstraints (#48525) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48525 Fixes https://github.com/facebook/react-native/issues/48249 `TextMeasureCacheKey` hash and equality functions only incorporates the maximum width constraint. I'm guessing this was an attempt at an optimization, but it can lead to incorrect results in pretty trivial cases. E.g. if Yoga knows a definite size of `Text` in one dimension, and measures via `YGMeasureModeExactly`, we can have a minimum size corresponding specific to the style in which the text was laid out. Changelog: [General][Fixed] - Fix TextMeasureCacheKey Throwing Out Some LayoutConstraints Reviewed By: christophpurrer Differential Revision: D67922414 fbshipit-source-id: 0ee0220059fc4e4645b1684c42a0587fe728bedd --- .../react/renderer/textlayoutmanager/TextMeasureCache.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/TextMeasureCache.h b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/TextMeasureCache.h index 4a0fd56be48..0a9ff8c78d5 100644 --- a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/TextMeasureCache.h +++ b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/TextMeasureCache.h @@ -208,8 +208,7 @@ inline bool operator==( return areAttributedStringsEquivalentLayoutWise( lhs.attributedString, rhs.attributedString) && lhs.paragraphAttributes == rhs.paragraphAttributes && - lhs.layoutConstraints.maximumSize.width == - rhs.layoutConstraints.maximumSize.width; + lhs.layoutConstraints == rhs.layoutConstraints; } inline bool operator!=( @@ -243,7 +242,7 @@ struct hash { return facebook::react::hash_combine( attributedStringHashLayoutWise(key.attributedString), key.paragraphAttributes, - key.layoutConstraints.maximumSize.width); + key.layoutConstraints); } };