-
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] Fix error when pasting deeply nested structure content #55613
[RNMobile] Fix error when pasting deeply nested structure content #55613
Conversation
Size Change: +15 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
1501eff
to
750e095
Compare
Flaky tests detected in 750e095. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6642782371
|
// The following unit tests related to the `raw-handling` API will be enabled when addressing | ||
// the various errors we encounter when running them in the native version. | ||
// Reference: https://github.com/WordPress/gutenberg/issues/55652 | ||
const RAW_HANDLING_UNSUPPORTED_UNIT_TESTS = [ | ||
'html-formatting-remover', | ||
'phrasing-content-reducer', | ||
'ms-list-converter', | ||
'figure-content-reducer', | ||
'special-comment-converter', | ||
'normalise-blocks', | ||
'image-corrector', | ||
]; |
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.
We'll enable these unit tests when addressing #55652.
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've tested this on both iOS and Android, I also ran the unit tests for the raw-handling
functionality. 🚀
Yeah, it should ungroup the block. I'll take a look 👀, thanks for sharing it ! |
I managed to reproduce it. Looks like there's a bug related to the ungrouping logic used in the |
That sounds good to me, thank you for investigating it! |
For reference: #55738 |
What?
Fixes an error related to pasting content with complex structures that leads to hitting the maximum call stack size specified in Hermes (reference).
Why?
Fixes wordpress-mobile/WordPress-Android#18750 and wordpress-mobile/gutenberg-mobile#6123.
How?
The issue was produced due to the fact that the implementation of
Node.contains
was recursive. This function is used as part of the pasting functionality, so when a deeply nested structure is processed, the call stack could grow until it reaches the limit and crashes the editor.gutenberg/packages/react-native-editor/src/jsdom-patches.js
Line 42 in ae769e9
https://github.com/WordPress/gutenberg/blob/1501effca4cf99fd39c30b6f6d0f443e6b090c55/packages/blocks/src/api/raw-handling/utils.js#L128-L134
https://github.com/WordPress/gutenberg/blob/1501effca4cf99fd39c30b6f6d0f443e6b090c55/packages/blocks/src/api/raw-handling/utils.js#L153-L158
https://github.com/WordPress/gutenberg/blob/1501effca4cf99fd39c30b6f6d0f443e6b090c55/packages/blocks/src/api/raw-handling/paste-handler.js#L212
https://github.com/WordPress/gutenberg/blob/1501effca4cf99fd39c30b6f6d0f443e6b090c55/packages/block-editor/src/components/rich-text/index.native.js#L452-L453
The solution proposed is to replace the implementation with a non-recursive approach. In fact, the implementation has been copied from the original polyfill we use in WordPress core for the function
Node.contains
(reference 1, reference 2, reference 3). This polyfill is no longer used but we keep a reference (reference).deepFilterNodeList
is also recursive, hence we might still get the error after applying this fix. However, it's likely that would happen in very edge cases.Testing Instructions
Click here to display the HTML code
Testing Instructions for Keyboard
N/A
Screenshots or screencast
N/A