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

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

Conversation

@levibuzolic

@levibuzolic levibuzolic commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

Fixes #58157.

On iOS 17.2, a single-line TextInput with caretHidden can repeatedly log Surface 1073741823 x 1073741823 is too large as the caret moves. This can also stop XCUITest from considering the app idle.

The problem comes from returning CGRectZero for the caret.

This PR leaves the rectangle alone and hides the caret with a transparent tint instead. Non-empty selections still use selectionColor, so their highlights and handles remain visible.

The tint is also updated after typing replaces a selection, and when switching between single-line and multiline inputs. Otherwise, those transitions can leave the caret visible or lose the selection color.

Changelog:

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

Test Plan:

Built RNTester from source and ran RCTUITextFieldTests on an iPhone 16 simulator with iOS 18.0 and Xcode 27.1. All 10 tests passed with Address Sanitizer and Undefined Behavior Sanitizer enabled. The tests are now included in the RNTester unit-test target and run by iOS CI.

Also checked typing, replacing selected text, selection highlights and handles, and switching between single-line and multiline inputs in RNTester. The caret stayed hidden and selections kept their configured color. No matching surface errors appeared in the logs. Formatting checks passed.

The original iOS 17.2 repro produced 615 errors in 15 seconds before the fix and none afterward. I couldn't repeat that check after rebasing because the 17.2 runtime isn't installed here.

The full RNTester test build hit a Swift compatibility linker error in RNTesterIntegrationTests (__swift_FORCE_LOAD_$_swiftCompatibility56), so I ran the unit-test target separately. Mac Catalyst and physical devices weren't retested.

Native test command
xcodebuild test \
  -workspace packages/rn-tester/RNTesterPods.xcworkspace \
  -scheme RNTesterUnitTests \
  -configuration Debug \
  -sdk iphonesimulator \
  -destination 'platform=iOS Simulator,id=9FB84EC1-1702-4AD9-9E82-BAD3F5A2EC0F' \
  -derivedDataPath ../RNTesterBuild \
  -resultBundlePath ../CaretUnitTests5.xcresult \
  -enableAddressSanitizer YES \
  -enableUndefinedBehaviorSanitizer YES \
  -only-testing:RNTesterUnitTests/RCTUITextFieldTests \
  CODE_SIGNING_ALLOWED=NO

@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 27, 2026
@levibuzolic levibuzolic changed the title Fix iOS Metal errors when TextInput caret is hidden Fix iOS 17 Metal errors when TextInput caret is hidden Aug 27, 2026
@levibuzolic
levibuzolic marked this pull request as ready for review August 27, 2026 06:51
@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 27, 2026
Preserve UIKit caret geometry and hide collapsed carets with transparent tint.
Restore selection tint when ranges expand, collapse during typing, or move to
a new backing view.

Exercise the caret transitions in RNTesterUnitTests and run the focused suite
in iOS CI. Include the existing Swift import probe in the unit-test target so
Xcode links the Swift support libraries required by React Native's dependencies.
@levibuzolic
levibuzolic force-pushed the fix/text-input-caret-hidden-surface-too-large branch from 282baa0 to 761a5ff Compare October 28, 2026 05:51

This branch has not been deployed

No deployments
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.

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

1 participant