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
This commit is contained in:
KirtiRamchandani authored and meta-codesync[bot] committed 2026-05-27 02:03:34 -07:00
1 parent 5fce2de800
commit 98d07b3d45
2 files changed
+36 -6

No files matched your search

@@ -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,
@@ -5,14 +5,42 @@
* LICENSE file in the root directory of this source tree.
*/
#include <memory>
#include <gtest/gtest.h>
#include <react/renderer/textlayoutmanager/TextLayoutManager.h>
#include <react/renderer/textlayoutmanager/TextMeasureCache.h>
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));
}