From 750e095f4b6b88f68bade01e0959d872d35c2383 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Wed, 25 Oct 2023 09:38:45 +0200 Subject: [PATCH 1/3] Update `Node.contains` polyfill --- .../react-native-editor/src/jsdom-patches.js | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/react-native-editor/src/jsdom-patches.js b/packages/react-native-editor/src/jsdom-patches.js index 73f11ef55e4a4b..f33dd892f8c18c 100644 --- a/packages/react-native-editor/src/jsdom-patches.js +++ b/packages/react-native-editor/src/jsdom-patches.js @@ -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; }; /** From ee6558799fa4d5436dc3143b47c743451465ee02 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Wed, 25 Oct 2023 09:52:50 +0200 Subject: [PATCH 2/3] Enable some of the `raw-handling` unit tests in the native version --- test/native/jest.config.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/native/jest.config.js b/test/native/jest.config.js index 7ecbf8036a03c4..ad5c794ebbce88 100644 --- a/test/native/jest.config.js +++ b/test/native/jest.config.js @@ -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. @@ -29,6 +42,10 @@ module.exports = { '/test/**/*.native.[jt]s?(x)', '/**/test/!(helper)*.native.[jt]s?(x)', '/packages/react-native-*/**/?(*.)+(spec|test).[jt]s?(x)', + // Enable `raw-handling` API unit tests to check jsdom patches. + `/packages/blocks/src/api/raw-handling/**/test/!(${ RAW_HANDLING_UNSUPPORTED_UNIT_TESTS.join( + '|' + ) }).[jt]s?(x)`, ], testPathIgnorePatterns: [ '/node_modules/', '/__device-tests__/' ], testEnvironmentOptions: { From 887979a55e834065a870a9fdba6e6f1d1bad8c22 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Thu, 26 Oct 2023 18:13:22 +0200 Subject: [PATCH 3/3] Update `react-native-editor` changelog --- packages/react-native-editor/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/react-native-editor/CHANGELOG.md b/packages/react-native-editor/CHANGELOG.md index 9077664ca60be2..cd7f4dc3d4aa21 100644 --- a/packages/react-native-editor/CHANGELOG.md +++ b/packages/react-native-editor/CHANGELOG.md @@ -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]