-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RNMobile: Avoid crashes by ensuring RichText value exists prior to toString
calls
#58088
Conversation
With this commit, checks are added to ensure the RichText value exists before making a toString call. The aim is to avoid any crashes taking places when the value is undefined.
toString
calls
Size Change: 0 B Total Size: 1.7 MB ℹ️ View Unchanged
|
Note: The four failing PHP tests are failing for all recent PRs (example). I don't believe they're related to the changes here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎊 !
I tested using the instructions from the PR and couldn't reproduce the exception. As a side note, I also reproduced the crash before using this fix by applying the following patch:
diff --git forkSrcPrefix/packages/block-editor/src/components/rich-text/native/index.native.js forkDstPrefix/packages/block-editor/src/components/rich-text/native/index.native.js
index 1f536011b35b6f132868bd4b49316f989ee7344a..41287c779458b5938a121ef17500722aa73e2b45 100644
--- forkSrcPrefix/packages/block-editor/src/components/rich-text/native/index.native.js
+++ forkDstPrefix/packages/block-editor/src/components/rich-text/native/index.native.js
@@ -157,6 +157,7 @@ export class RichText extends Component {
// Internal values that are update synchronously, unlike props.
this.value = value;
+ this.value = undefined;
this.selectionStart = selectionStart;
this.selectionEnd = selectionEnd;
}
Flaky tests detected in 554ca4a. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7615402692
|
* Release script: Update react-native-editor version to 1.110.0 * Release script: Update CHANGELOG for version 1.110.0 * Release script: Update podfile * RNMobile: Avoid crashes by ensuring RichText value exists prior to `toString` calls (#58088) * Release script: Update react-native-editor version to 1.110.1 * Release script: Update CHANGELOG for version 1.110.1 * Release script: Update podfile * Revert version to 1.111.0 --------- Co-authored-by: Gerardo <[email protected]> Co-authored-by: Siobhan Bamber <[email protected]> Co-authored-by: Derek Blank <[email protected]> Co-authored-by: Carlos Garcia <[email protected]>
For reference, I managed to reproduce the crash with the following steps:
|
* Release script: Update react-native-editor version to 1.111.0 * Release script: Update CHANGELOG for version 1.111.0 * Release script: Update podfile * [RNMobile] Video block: Fix logic for displaying empty state based on source presence (#58015) * Avoid displaying Video block empty state when a source is present * Add tests to cover empty state visibility logic * Update `react-native-editor` changelog * Remove unneeded `await` statements from Video block unit tests * Update `react-native-editor` changelog * Release script: Update react-native-editor version to 1.111.1 * Release script: Update CHANGELOG for version 1.111.1 * Release script: Update podfile * RNMobile: Avoid crashes by ensuring RichText value exists prior to `toString` calls (#58088) * [RNMobile] Remove `mediaFilesCollectionBlock` initial prop (#58140) * Remove `mediaFilesCollectionBlock` initial prop * Remove `enableMediaFilesCollectionBlocks` from Gutenberg demo app * Release script: Update react-native-editor version to 1.111.2 * Release script: Update CHANGELOG for version 1.111.2 * Release script: Update podfile --------- Co-authored-by: Siobhan <[email protected]>
Fixes wordpress-mobile/WordPress-iOS#22432
toString
calls wordpress-mobile/gutenberg-mobile#6563What?
In this PR, we ensure the RichText value exists prior to making a
toString
call.Why?
We've received several crash reports in the most recent WPiOS release (
24.0
) that point to a failedtoString
call:As per the discussion and extra logs in wordpress-mobile/WordPress-iOS#22432, we believe this emerged following the changes in #57028, with the cause being that the RichText value can sometimes be undefined.
How?
Optional chaining has been used to ensure the RichText value exists prior to making the
onString
call. If it doesn't, the call will now fail gracefully, without crashing the app.Note, we've had difficulty reproducing the crash. We believe it's root cause is performance related, as described here. As such, the proposed fix in this PR is considered a temporary patch, and the hope is to address the more complex performance-related issues separately.
Testing Instructions
Due to the difficulty reproducing the crash, there aren't specific steps to ensure the fix resolves it. We can, however, manually set the RichText value to
undefined
locally, and verify the app does not crash: