From abd34560817ac33962b1152f2e8f2d28fe6e8892 Mon Sep 17 00:00:00 2001 From: Gregory Moskaliuk Date: Tue, 27 Oct 2026 11:21:29 +0100 Subject: [PATCH] Share iOS text measurements that differ only in unused constraints The native iOS measurement depends only on the maximum width, and the result is clamped to the full constraints after the cache, so the minimum size and the maximum height are left out of the cache key. Co-Authored-By: Claude Opus 5.5 --- .../react/renderer/textlayoutmanager/TextLayoutManager.mm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/TextLayoutManager.mm b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/TextLayoutManager.mm index 0f2fbe82b8f5..09ad2c43f9e5 100644 --- a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/TextLayoutManager.mm +++ b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/TextLayoutManager.mm @@ -8,6 +8,7 @@ #import "TextLayoutManager.h" #import "RCTTextLayoutManager.h" +#import #import #import @@ -53,10 +54,15 @@ const auto &attributedString = placeholderAttributedString ? *placeholderAttributedString : originalAttributedString; + // The native measurement depends only on the maximum width, and the result is clamped to the + // full constraints below, outside the cache, so the rest is left out of the key. + LayoutConstraints keyConstraints = layoutConstraints; + keyConstraints.minimumSize = Size{}; + keyConstraints.maximumSize.height = std::numeric_limits::infinity(); measurement = textMeasureCache_.get( {.attributedString = attributedString, .paragraphAttributes = paragraphAttributes, - .layoutConstraints = layoutConstraints, + .layoutConstraints = keyConstraints, .pointScaleFactor = layoutContext.pointScaleFactor}, [&]() { auto telemetry = TransactionTelemetry::threadLocalTelemetry();