mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
fix(ios): replace crash-causing RCTAssert with RCTLogWarn in touch handler (#57696)
Summary:
On iOS 17+, UITextView's text selection gesture recognizer can deliver `touchesMoved:`/`touchesEnded:` to `RCTSurfaceTouchHandler` without a prior `touchesBegan:` for the same touch. This happens because UIKit's internal selection gesture claims the touch begin exclusively and only forwards subsequent phases to sibling gesture recognizers.
When this occurs, `_activeTouches.find(touch)` returns `end()`, and the `RCTAssert` fires, throwing an `NSException` that crashes the app in debug builds. The existing `if (iterator == end) { continue; }` guard already handles this case gracefully (and is the only code path exercised in release builds, where `RCTAssert` is a no-op).
This PR downgrades the assertion to `RCTLogWarn`, preserving the diagnostic signal while eliminating the debug-only crash.
This issue was discovered while investigating text selection crashes in [react-native-enriched-markdown](https://github.com/nicolo-ribaudo/react-native-enriched-markdown), where a custom `UITextView`-based Fabric component with rich text formatting (headings, paragraphs) consistently triggers the assertion during normal selection gestures.
## Changelog:
[iOS] [Fixed] - Fix debug-only crash in RCTSurfaceTouchHandler from UITextView text-selection gestures on iOS 17+
Pull Request resolved: https://github.com/react/react-native/pull/57696
Test Plan:
1. Create a React Native app with a multiline `<TextInput>` or a custom `UITextView`-based Fabric component
2. On iOS 17+ simulator or device, in a **debug** build:
- Tap to place the cursor in a text block
- Attempt to select text by long-pressing and dragging to a different paragraph
3. **Before this fix**: App crashes with `NSException: "Inconsistency between local and UIKit touch registries"`
4. **After this fix**: Selection works normally. A warning is logged to the console: `"Inconsistency between local and UIKit touch registries"`
5. Verified that release builds are unaffected (RCTAssert was already a no-op in release)
Reviewed By: javache
Differential Revision: D113753196
Pulled By: fabriziocucci
fbshipit-source-id: d4cb867818f88c4f111628d115c6be98b257f09c
This commit is contained in:
1 parent
3e2403327c
commit
433e79d2f4
1 file changed
+4
-3
@@ -8,6 +8,7 @@
|
||||
#import "RCTSurfaceTouchHandler.h"
|
||||
|
||||
#import <React/RCTIdentifierPool.h>
|
||||
#import <React/RCTLog.h>
|
||||
#import <React/RCTUtils.h>
|
||||
#import <React/RCTViewComponentView.h>
|
||||
|
||||
@@ -206,8 +207,8 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithTarget : (id)target action : (SEL)act
|
||||
{
|
||||
for (UITouch *touch in touches) {
|
||||
auto iterator = _activeTouches.find(touch);
|
||||
RCTAssert(iterator != _activeTouches.end(), @"Inconsistency between local and UIKit touch registries");
|
||||
if (iterator == _activeTouches.end()) {
|
||||
RCTLogWarn(@"Inconsistency between local and UIKit touch registries");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -219,8 +220,8 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithTarget : (id)target action : (SEL)act
|
||||
{
|
||||
for (UITouch *touch in touches) {
|
||||
auto iterator = _activeTouches.find(touch);
|
||||
RCTAssert(iterator != _activeTouches.end(), @"Inconsistency between local and UIKit touch registries");
|
||||
if (iterator == _activeTouches.end()) {
|
||||
RCTLogWarn(@"Inconsistency between local and UIKit touch registries");
|
||||
continue;
|
||||
}
|
||||
auto &activeTouch = iterator->second;
|
||||
@@ -236,8 +237,8 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithTarget : (id)target action : (SEL)act
|
||||
|
||||
for (UITouch *touch in touches) {
|
||||
auto iterator = _activeTouches.find(touch);
|
||||
RCTAssert(iterator != _activeTouches.end(), @"Inconsistency between local and UIKit touch registries");
|
||||
if (iterator == _activeTouches.end()) {
|
||||
RCTLogWarn(@"Inconsistency between local and UIKit touch registries");
|
||||
continue;
|
||||
}
|
||||
activeTouches.push_back(iterator->second);
|
||||
|
||||
Reference in new issue
Block a user