Skip to content

Fix iOS crash when truncating composed text - #58101

Open
gooddev97 wants to merge 1 commit into
react:mainfrom
gooddev97:fix/ios-truncated-composed-text-crash
Open

Fix iOS crash when truncating composed text#58101
gooddev97 wants to merge 1 commit into
react:mainfrom
gooddev97:fix/ios-truncated-composed-text-crash

Conversation

@gooddev97

Copy link
Copy Markdown
Contributor

Summary:

Fixes #57499.

processTruncatedAttributedText updated color attributes while NSLayoutManager was enumerating line fragments. When the truncation boundary landed inside a composed character sequence, TextKit attribute fixing could invalidate the glyph-to-character mapping and later raise NSRangeException.

This change:

  • records the truncated character range during line enumeration and applies attributes afterward in one edit transaction;
  • clamps and expands the range to full composed character sequences;
  • clamps highlighted-character enumeration to the current text storage length;
  • adds regression coverage for mutation timing/range handling and the Unicode width-sweep reproducer from the issue.

Changelog:

[IOS] [FIXED] - Prevent crashes when text truncation splits a composed character sequence.

Test Plan:

  • yarn clang-format packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm packages/react-native/React/Tests/Text/RCTTextLayoutManagerTests.mm — passed.
  • Temporarily enabled the React-RCTFabric/Tests testspec in the local RNTester Podfile (not part of this change), then ran:
xcodebuild test -quiet \
  -workspace RNTesterPods.xcworkspace \
  -scheme React-RCTFabric-Unit-Tests \
  -sdk iphonesimulator \
  -destination "platform=iOS Simulator,id=B3D3DA0E-E608-4CBE-A8FC-F5A0C328629B" \
  -derivedDataPath /tmp/RCTFabricTextLayoutBuild \
  -only-testing:React-RCTFabric-Unit-Tests/RCTTextLayoutManagerTests \
  EXCLUDED_SOURCE_FILE_NAMES="RCTAttributedTextUtilsTest.mm RCTParagraphComponentViewTests.mm RCTTextInputUtilsTest.mm RCTComponentViewRegistryTests.mm RCTScrollViewComponentViewTests.mm RCTViewComponentViewTests.mm RCTViewComponentViewUnmountTests.mm" \
  LIBRARY_SEARCH_PATHS="$(inherited) /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator"

Result: both RCTTextLayoutManagerTests tests passed on an iPhone 17 Pro simulator running iOS 26.5. The targeted regression test was also verified to fail before the fix and pass afterward.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 24, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

iOS: NSRangeException crash drawing truncated <Text> when the ellipsis boundary splits a composed character cluster (processTruncatedAttributedText)

1 participant