From 850496b739749a969cea8a1e7973287eeab760b5 Mon Sep 17 00:00:00 2001 From: Autopilot Bot Date: Thu, 22 Oct 2026 12:15:13 -0700 Subject: [PATCH] Skip image-paste pasteboard probe in TextInput to avoid main-thread hangs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: WARNING: Generated by Autopilot (alpha) — review carefully, verify the underlying claim before accepting. Agent: [React Native Agent (Bugs)](https://www.internalfb.com/autopilot/marketplace?agent=1645742253726459) | Trajectory: https://www.internalfb.com/intern/devai/devmate/inspector/dea80a9f-a635-4ecc-874d-33f0741108ca/ | SC job: https://www.internalfb.com/intern/sandcastle/instance/9007202303535554/ --- When the app returns to the foreground with a TextInput focused, UIKit refreshes the keyboard's paste support. To decide whether the field supports image paste, UIKit calls `-[RCTUITextView canPerformAction:withSender:]` with `paste:`. `super` then synchronously queries the system pasteboard over XPC on the main thread. If the pasteboard service is slow to reply, the main thread blocks long enough for the system to terminate the app. This diff overrides `supportsImagePaste` to return `NO` in `RCTUITextView` and `RCTUITextField`, so UIKit skips that pasteboard query. TextInput only accepts text, so no image paste capability is lost. `canPerformAction:` and `paste:` are unchanged, so the edit menu and text paste work as before. Changelog: [iOS][Fixed] - Avoid a synchronous main-thread pasteboard query (and possible app hang) when a focused TextInput's keyboard becomes active on app foreground Reviewed By: cortinico Differential Revision: D125922446 --- .../Libraries/Text/TextInput/Multiline/RCTUITextView.mm | 9 +++++++++ .../Text/TextInput/Singleline/RCTUITextField.mm | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.mm b/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.mm index d0146ab6e64..eef87f87f63 100644 --- a/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.mm +++ b/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.mm @@ -348,6 +348,15 @@ - (BOOL)canPerformAction:(SEL)action withSender:(id)sender return [super canPerformAction:action withSender:sender]; } +// UIKit queries this when the keyboard becomes active, including when the app returns to the +// foreground. The default implementation calls `canPerformAction:` with `paste:`, which +// synchronously queries the system pasteboard on the main thread and can hang the app. TextInput +// only accepts text, so opt out of image paste; text paste is unaffected. +- (BOOL)supportsImagePaste +{ + return NO; +} + - (void)buildMenuWithBuilder:(id)builder { #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 170000 && !TARGET_OS_TV diff --git a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm index f747d08ff51..8f07036e875 100644 --- a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm +++ b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm @@ -196,6 +196,15 @@ - (BOOL)canPerformAction:(SEL)action withSender:(id)sender return [super canPerformAction:action withSender:sender]; } +// UIKit queries this when the keyboard becomes active, including when the app returns to the +// foreground. The default implementation calls `canPerformAction:` with `paste:`, which +// synchronously queries the system pasteboard on the main thread and can hang the app. TextInput +// only accepts text, so opt out of image paste; text paste is unaffected. +- (BOOL)supportsImagePaste +{ + return NO; +} + - (void)buildMenuWithBuilder:(id)builder { #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 170000