From 98d07b3d45da11d5ced6c8e7e7148eb982dffb5a Mon Sep 17 00:00:00 2001 From: KirtiRamchandani Date: Wed, 27 May 2026 02:03:34 -0700 Subject: [PATCH] Fix text layout cache key for maxFontSizeMultiplier (#56960) Summary: Text layout measurement cache keys currently consider `fontSizeMultiplier` and `allowFontScaling`, but omit `maxFontSizeMultiplier`. When that cap changes, Fabric can reuse a stale measurement even though the effective scaled font size may change. This adds `maxFontSizeMultiplier` to the layout-wise text attribute equality and hash helpers, and covers the cache-key behavior with focused C++ tests. Fixes https://github.com/facebook/react-native/issues/56921. ## Changelog: [GENERAL] [FIXED] - Include `maxFontSizeMultiplier` in Fabric text layout cache keys. Pull Request resolved: https://github.com/facebook/react-native/pull/56960 Test Plan: - `npx --yes clang-format --dry-run --Werror packages/react-native/ReactCommon/react/renderer/textlayoutmanager/tests/TextLayoutManagerTest.cpp` - `git diff --check` I could not run the native gtest target locally from this sparse checkout; the patch adds focused coverage in the existing `TextLayoutManagerTest.cpp` file. Reviewed By: sammy-SC Differential Revision: D106362229 Pulled By: javache fbshipit-source-id: 8977afe60b497344713af437eec48d5340eaed6c --- .../textlayoutmanager/TextMeasureCache.h | 4 +- .../tests/TextLayoutManagerTest.cpp | 38 ++++++++++++++++--- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/TextMeasureCache.h b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/TextMeasureCache.h index b4becb8f2e1..cb3a6000c30 100644 --- a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/TextMeasureCache.h +++ b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/TextMeasureCache.h @@ -130,7 +130,8 @@ inline bool areTextAttributesEquivalentLayoutWise(const TextAttributes &lhs, con rhs.dynamicTypeRamp, rhs.alignment) && floatEquality(lhs.fontSize, rhs.fontSize) && floatEquality(lhs.fontSizeMultiplier, rhs.fontSizeMultiplier) && - floatEquality(lhs.letterSpacing, rhs.letterSpacing) && floatEquality(lhs.lineHeight, rhs.lineHeight); + floatEquality(lhs.letterSpacing, rhs.letterSpacing) && floatEquality(lhs.lineHeight, rhs.lineHeight) && + floatEquality(lhs.maxFontSizeMultiplier, rhs.maxFontSizeMultiplier); } inline size_t textAttributesHashLayoutWise(const TextAttributes &textAttributes) @@ -145,6 +146,7 @@ inline size_t textAttributesHashLayoutWise(const TextAttributes &textAttributes) textAttributes.fontStyle, textAttributes.fontVariant, textAttributes.allowFontScaling, + textAttributes.maxFontSizeMultiplier, textAttributes.dynamicTypeRamp, textAttributes.letterSpacing, textAttributes.lineHeight, diff --git a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/tests/TextLayoutManagerTest.cpp b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/tests/TextLayoutManagerTest.cpp index 40258861855..8d1152bcc9a 100644 --- a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/tests/TextLayoutManagerTest.cpp +++ b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/tests/TextLayoutManagerTest.cpp @@ -5,14 +5,42 @@ * LICENSE file in the root directory of this source tree. */ -#include - #include -#include +#include using namespace facebook::react; -TEST(TextLayoutManagerTest, testSomething) { - // TODO: +TEST(TextLayoutManagerTest, defaultTextAttributesAreLayoutEquivalent) { + TextAttributes lhs; + TextAttributes rhs; + + EXPECT_TRUE(areTextAttributesEquivalentLayoutWise(lhs, rhs)); + EXPECT_EQ( + textAttributesHashLayoutWise(lhs), textAttributesHashLayoutWise(rhs)); +} + +TEST(TextLayoutManagerTest, maxFontSizeMultiplierAffectsLayoutCacheEquality) { + TextAttributes lhs; + TextAttributes rhs; + + lhs.fontSize = rhs.fontSize = 16; + lhs.fontSizeMultiplier = rhs.fontSizeMultiplier = 2; + lhs.maxFontSizeMultiplier = 1; + rhs.maxFontSizeMultiplier = 2; + + EXPECT_FALSE(areTextAttributesEquivalentLayoutWise(lhs, rhs)); +} + +TEST(TextLayoutManagerTest, maxFontSizeMultiplierAffectsLayoutCacheHash) { + TextAttributes lhs; + TextAttributes rhs; + + lhs.fontSize = rhs.fontSize = 16; + lhs.fontSizeMultiplier = rhs.fontSizeMultiplier = 2; + lhs.maxFontSizeMultiplier = 1; + rhs.maxFontSizeMultiplier = 2; + + EXPECT_NE( + textAttributesHashLayoutWise(lhs), textAttributesHashLayoutWise(rhs)); }