Skip to content

Commit 42f2ded

Browse files
sherginfacebook-github-bot
authored andcommitted
Fabric: Returning zero size on attempt to measure an empty string in RCTTextLayoutManager
Summary: Sometimes, very irregularly, measuring an empty string crashes/freezes iOS internal text infrastructure. This is our last line of defense. Changelog: [Internal] Fabric-specific internal change. Reviewed By: sammy-SC, mdvacca Differential Revision: D18802308 fbshipit-source-id: addf523b31b78b0777be7eeaeee140ac8416393b
1 parent d12385c commit 42f2ded

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

ReactCommon/fabric/textlayoutmanager/platform/ios/RCTTextLayoutManager.mm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ static NSLineBreakMode RCTNSLineBreakModeFromEllipsizeMode(EllipsizeMode ellipsi
3636
paragraphAttributes:(ParagraphAttributes)paragraphAttributes
3737
layoutConstraints:(LayoutConstraints)layoutConstraints
3838
{
39+
if (attributedString.length == 0) {
40+
// This is not really an optimization because that should be checked much earlier on the call stack.
41+
// Sometimes, very irregularly, measuring an empty string crashes/freezes iOS internal text infrastructure.
42+
// This is our last line of defense.
43+
return layoutConstraints.clamp({0, 0});
44+
}
45+
3946
CGSize maximumSize = CGSize{layoutConstraints.maximumSize.width,
4047
layoutConstraints.maximumSize.height};
4148
NSTextStorage *textStorage = [self _textStorageAndLayoutManagerWithAttributesString:attributedString

0 commit comments

Comments
 (0)