Skip to content

Commit 15dda0a

Browse files
tido64facebook-github-bot
authored andcommitted
Fix multiline TextInput crash when inserting/removing lots of text (#29307)
Summary: Multiline `TextInput` can crash when really long texts are inserted and removed quickly. This is caused by the fact that [`-[NSAttributedString string]`](https://developer.apple.com/documentation/foundation/nsattributedstring/1412616-string?language=objc) doesn't really return a copy, and may mutate the string while it is being used by `convertIdToFollyDynamic`. See microsoft#489 (comment) for more details on the issue. This issue was originally reported in microsoft#486 and was fixed in microsoft#489. ## Changelog [iOS] [Fixed] - Fix multiline TextInput crash when inserting/removing lots of text Pull Request resolved: #29307 Test Plan: 1. Open RNTester > TextInput 2. Search for a multiline example 3. Copy some large text and paste it into the text input view 4. Remove some (or all) text 5. Repeat steps 3-4 Reviewed By: shergin Differential Revision: D22488854 Pulled By: JoshuaGross fbshipit-source-id: 6fab7818d68538450d93460361ff5934caf86c10
1 parent 3137c44 commit 15dda0a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Libraries/Text/TextInput/RCTBaseTextInputView.m

+6-6
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ - (void)textInputDidBeginEditing
333333

334334
[_eventDispatcher sendTextEventWithType:RCTTextEventTypeFocus
335335
reactTag:self.reactTag
336-
text:self.backedTextInputView.attributedText.string
336+
text:[self.backedTextInputView.attributedText.string copy]
337337
key:nil
338338
eventCount:_nativeEventCount];
339339
}
@@ -347,13 +347,13 @@ - (void)textInputDidEndEditing
347347
{
348348
[_eventDispatcher sendTextEventWithType:RCTTextEventTypeEnd
349349
reactTag:self.reactTag
350-
text:self.backedTextInputView.attributedText.string
350+
text:[self.backedTextInputView.attributedText.string copy]
351351
key:nil
352352
eventCount:_nativeEventCount];
353353

354354
[_eventDispatcher sendTextEventWithType:RCTTextEventTypeBlur
355355
reactTag:self.reactTag
356-
text:self.backedTextInputView.attributedText.string
356+
text:[self.backedTextInputView.attributedText.string copy]
357357
key:nil
358358
eventCount:_nativeEventCount];
359359
}
@@ -367,7 +367,7 @@ - (BOOL)textInputShouldReturn
367367
// (no connection to any specific "submitting" process).
368368
[_eventDispatcher sendTextEventWithType:RCTTextEventTypeSubmit
369369
reactTag:self.reactTag
370-
text:self.backedTextInputView.attributedText.string
370+
text:[self.backedTextInputView.attributedText.string copy]
371371
key:nil
372372
eventCount:_nativeEventCount];
373373

@@ -422,7 +422,7 @@ - (NSString *)textInputShouldChangeText:(NSString *)text inRange:(NSRange)range
422422
}
423423
}
424424

425-
NSString *previousText = backedTextInputView.attributedText.string ?: @"";
425+
NSString *previousText = [backedTextInputView.attributedText.string copy] ?: @"";
426426

427427
if (range.location + range.length > backedTextInputView.attributedText.string.length) {
428428
_predictedText = backedTextInputView.attributedText.string;
@@ -468,7 +468,7 @@ - (void)textInputDidChange
468468

469469
if (_onChange) {
470470
_onChange(@{
471-
@"text": self.attributedText.string,
471+
@"text": [self.attributedText.string copy],
472472
@"target": self.reactTag,
473473
@"eventCount": @(_nativeEventCount),
474474
});

0 commit comments

Comments
 (0)