Skip to content

Fix iOS 17 Metal errors when TextInput caret is hidden - #58158

Open
levibuzolic wants to merge 1 commit into
react:mainfrom
levibuzolic:fix/text-input-caret-hidden-surface-too-large
Open

Fix iOS 17 Metal errors when TextInput caret is hidden#58158
levibuzolic wants to merge 1 commit into
react:mainfrom
levibuzolic:fix/text-input-caret-hidden-surface-too-large

Conversation

@levibuzolic

@levibuzoliclevibuzolic commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Summary:

Fixes#58157.

On iOS 17.2, caretHidden makes a single-line TextInput return CGRectZero from caretRectForPosition:. When the caret moves, Core Animation repeatedly logs Surface 1073741823 x 1073741823 is too large. This activity can prevent XCUITest from detecting an idle app.

This change keeps the caret geometry intact and hides a collapsed caret with a transparent tint. It restores the requested selectionColor for non-empty selections so the highlight and handles remain visible. Fabric also reapplies selectionColor after switching between single-line and multiline backing views.

Changelog:

[IOS] [FIXED] - Prevent hidden TextInput carets from causing repeated Metal surface errors.

Test Plan:

  • Ran clang-format on all changed Objective-C files:

    yarn clang-format packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm packages/react-native/React/Tests/Text/RCTUITextFieldTests.mm

    Result: passed.

  • Built the from-source HelloWorld app:

    xcodebuild -workspace private/helloworld/ios/HelloWorld.xcworkspace -scheme HelloWorld -configuration Debug -sdk iphonesimulator -destination 'generic/platform=iOS Simulator' CODE_SIGNING_ALLOWED=NO build

    Result: BUILD SUCCEEDED.

  • Syntax-checked the new Objective-C++ test file:

    RN_SIM_SDK=$(xcrun --sdk iphonesimulator --show-sdk-path)
    RN_SIM_PLATFORM=$(xcrun --sdk iphonesimulator --show-sdk-platform-path)
    xcrun clang++ -fsyntax-only -x objective-c++ -std=c++20 -fobjc-arc -fmodules -fcxx-modules -target arm64-apple-ios15.1-simulator -isysroot "$RN_SIM_SDK" -F "$RN_SIM_PLATFORM/Developer/Library/Frameworks" -I private/helloworld/ios/Pods/Headers/Public/React-Core packages/react-native/React/Tests/Text/RCTUITextFieldTests.mm

    Result: passed.

  • Tested private/helloworld on an iPhone SE 3 simulator with iOS 17.2:

    • Before this change: 615 matching Core Animation errors in 15 seconds.
    • After this change: 0 matching errors in 15 seconds.
    • The caret remained hidden while typing, after refocusing, in dark mode, and with a dimmed tint.
    • A non-empty selection kept its configured red highlight and handles.
    • caretHidden={false} kept its visible red caret.
  • Tested the same states on iOS 18.0. Both the hidden caret and selection highlight behaved correctly, with no matching errors.

  • Tested a native Mac Catalyst harness on macOS 26. A transparent tint hid the caret.

Caret-hiding experiments

These results came from iOS 17.2 during 10 seconds of caret movement:

StrategyCaret hiddenErrors
Normal caretNo0
CGRectZeroYes160
Zero width, valid origin and heightYes66
Zero height, valid origin and widthYes160
Valid rectangle moved off-screenYes164
Valid rectangle above the textYes158
CGRectNullYes169
0.01pt widthNo0
Transparent tintColorYes0

References

Apple documentation:

Repository history:

  • e13b9c6e49 (2017-05-29) — the CGRectZero override already existed at this point, so the implementation predates iOS 17 by several years. It was correct when written; iOS 17 changed caret rendering underneath it.
  • #38679 — the scrollRangeToVisible: no-op referenced in RCTUITextField.mm.

Apple's documentation does not mention the oversized-surface behaviour, and no public report of the Surface 1073741823 x 1073741823 is too large message could be found. The version range in this document comes from local measurement.

@meta-clameta-claBot 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 27, 2026
@levibuzoliclevibuzolic changed the title Fix iOS Metal errors when TextInput caret is hiddenFix iOS 17 Metal errors when TextInput caret is hiddenAug 27, 2026
@levibuzolic
levibuzolic marked this pull request as ready for review August 27, 2026 06:51
@facebook-github-toolsfacebook-github-toolsBot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Aug 27, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.Shared with MetaApplied 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.

Setting caretHidden for a TextInput component on iOS (iPhone SE 3) causes continuous metal rendering errors

1 participant

@levibuzolic