Skip to content

Commit 850496b

Browse files
Autopilot Botfacebook-github-bot
authored andcommitted
Skip image-paste pasteboard probe in TextInput to avoid main-thread hangs
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
1 parent ba0b3db commit 850496b

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

‎packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.mm‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,15 @@ - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
348348
return [super canPerformAction:action withSender:sender];
349349
}
350350

351+
// UIKit queries this when the keyboard becomes active, including when the app returns to the
352+
// foreground. The default implementation calls `canPerformAction:` with `paste:`, which
353+
// synchronously queries the system pasteboard on the main thread and can hang the app. TextInput
354+
// only accepts text, so opt out of image paste; text paste is unaffected.
355+
- (BOOL)supportsImagePaste
356+
{
357+
return NO;
358+
}
359+
351360
- (void)buildMenuWithBuilder:(id<UIMenuBuilder>)builder
352361
{
353362
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 170000 && !TARGET_OS_TV

‎packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,15 @@ - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
196196
return [super canPerformAction:action withSender:sender];
197197
}
198198

199+
// UIKit queries this when the keyboard becomes active, including when the app returns to the
200+
// foreground. The default implementation calls `canPerformAction:` with `paste:`, which
201+
// synchronously queries the system pasteboard on the main thread and can hang the app. TextInput
202+
// only accepts text, so opt out of image paste; text paste is unaffected.
203+
- (BOOL)supportsImagePaste
204+
{
205+
return NO;
206+
}
207+
199208
- (void)buildMenuWithBuilder:(id<UIMenuBuilder>)builder
200209
{
201210
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 170000

0 commit comments

Comments
 (0)