Skip to content
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

Merged
merged 3 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/react-native-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ For each user feature we should also add a importance categorization label to i
## Unreleased
- [*] Synced Patterns: Fix visibility of heading section when used with block based themes in dark mode [#55399]
- [*] Classic block: Add option to convert to blocks [#55461]
- [*] Fix error when pasting deeply nested structure content [#55613]

## 1.106.0
- [*] Exit Preformatted and Verse blocks by triple pressing the Return key [#53354]
Expand Down
24 changes: 13 additions & 11 deletions packages/react-native-editor/src/jsdom-patches.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,25 @@ const { NO_MODIFICATION_ALLOWED_ERR, HIERARCHY_REQUEST_ERR, NOT_FOUND_ERR } =
core;

/**
* Simple recursive implementation of Node.contains method
* Copy of Node.contains polyfill from polyfill-library package (https://t.ly/mehjW).
* This polyfill was originally used in WordPress Core (https://t.ly/4o7wQ).
*
* @param {number} otherNode Another node (may be the same node).
* @return {boolean} true if otherNode is a descendant of this node, or is this
* node, false otherwise.
* @param {number} node Node to check.
* @return {boolean} true if passed node is a descendant of this node, or the
* same node, false otherwise.
*
* This function is necessary in the mobile environment, because there are code
* paths that make use of functions in the Gutenberg (web) project, which has
* expectation that this is implemented (as it is in the browser environment).
*/
Node.prototype.contains = function ( otherNode ) {
return (
this === otherNode ||
Array.prototype.some.call( this._childNodes, ( childNode ) => {
return childNode.contains( otherNode );
} )
);
Node.prototype.contains = function ( node ) {
do {
if ( this === node ) {
return true;
}
} while ( ( node = node && node.parentNode ) );

return false;
};

/**
Expand Down
17 changes: 17 additions & 0 deletions test/native/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ const transpiledPackageNames = glob( 'packages/*/src/index.{js,ts}' ).map(
( fileName ) => fileName.split( '/' )[ 1 ]
);

// 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',
];
Comment on lines +21 to +32
Copy link
Contributor Author

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.


module.exports = {
rootDir: '../../',
// Automatically clear mock calls and instances between every test.
Expand All @@ -29,6 +42,10 @@ module.exports = {
'<rootDir>/test/**/*.native.[jt]s?(x)',
'<rootDir>/**/test/!(helper)*.native.[jt]s?(x)',
'<rootDir>/packages/react-native-*/**/?(*.)+(spec|test).[jt]s?(x)',
// Enable `raw-handling` API unit tests to check jsdom patches.
`<rootDir>/packages/blocks/src/api/raw-handling/**/test/!(${ RAW_HANDLING_UNSUPPORTED_UNIT_TESTS.join(
'|'
) }).[jt]s?(x)`,
],
testPathIgnorePatterns: [ '/node_modules/', '/__device-tests__/' ],
testEnvironmentOptions: {
Expand Down
Loading