Skip to content

Commit

Permalink
[RNMobile] Fix error when pasting deeply nested structure content (#5…
Browse files Browse the repository at this point in the history
…5613)

* Update `Node.contains` polyfill

* Enable some of the `raw-handling` unit tests in the native version

* Update `react-native-editor` changelog
  • Loading branch information
fluiddot authored Oct 31, 2023
1 parent b6a92c3 commit 435d90c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/react-native-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ For each user feature we should also add a importance categorization label to i
- [*] Social Icons: Fix visibility of inactive icons when used with block based themes in dark mode [#55398]
- [*] 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',
];

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

0 comments on commit 435d90c

Please sign in to comment.