From 0aa4d3646df3ba4c69fdc9c573b026c51060582b Mon Sep 17 00:00:00 2001 From: Ben Bowler Date: Mon, 4 Aug 2025 11:52:03 +0100 Subject: [PATCH 1/2] Remove console ignore in E2E block editor by polyfilling findLastIndex. --- assets/js/googlesitekit-polyfills.js | 30 ++++++++++++++++++++++++++++ tests/e2e/config/bootstrap.js | 6 ------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/assets/js/googlesitekit-polyfills.js b/assets/js/googlesitekit-polyfills.js index 9e20970a4a7..247b349ce1b 100644 --- a/assets/js/googlesitekit-polyfills.js +++ b/assets/js/googlesitekit-polyfills.js @@ -20,6 +20,36 @@ __webpack_public_path__ = `${ global._googlesitekitBaseData.assetsURL }js/`; async function loadPolyfills() { + // Add findLastIndex polyfill to prevent: + // `block-editor.js wp.blockEditor.transformStyles Failed to transform CSS. + // TypeError: tokenized.findLastIndex is not a function` + // errors blocks within Gutenberg built with node < v18. + if ( ! Array.prototype.findLastIndex ) { + Array.prototype.findLastIndex = function ( predicate, thisArg ) { + if ( this === null || this === undefined ) { + throw new TypeError( + 'Array.prototype.findLastIndex called on null or undefined' + ); + } + if ( typeof predicate !== 'function' ) { + throw new TypeError( 'predicate must be a function' ); + } + + const obj = Object( this ); + const len = parseInt( obj.length ) || 0; + + for ( let i = len - 1; i >= 0; i-- ) { + if ( i in obj ) { + const element = obj[ i ]; + if ( predicate.call( thisArg, element, i, obj ) ) { + return i; + } + } + } + return -1; + }; + } + if ( typeof global.IntersectionObserver === 'undefined' ) { await import( 'intersection-observer' ); } diff --git a/tests/e2e/config/bootstrap.js b/tests/e2e/config/bootstrap.js index 0d8968941b6..bc762419592 100644 --- a/tests/e2e/config/bootstrap.js +++ b/tests/e2e/config/bootstrap.js @@ -172,12 +172,6 @@ const IGNORE_CONSOLE_MESSAGES = [ matcher: 'startsWith', pattern: 'Warning: You are importing createRoot from', }, - // Gutenberg blockEditor.transformStyles warnings within the block editor. - { - matcher: 'includes', - pattern: - 'wp.blockEditor.transformStyles Failed to transform CSS. JSHandle@error', - }, ]; /** From c40706df9661996863f09b587b0f7fbb93ff2baf Mon Sep 17 00:00:00 2001 From: Ben Bowler Date: Wed, 13 Aug 2025 14:22:29 +0100 Subject: [PATCH 2/2] Ad debug logging where findLastIndex polyfill is required. --- assets/js/googlesitekit-polyfills.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/assets/js/googlesitekit-polyfills.js b/assets/js/googlesitekit-polyfills.js index 247b349ce1b..1b84c97ef39 100644 --- a/assets/js/googlesitekit-polyfills.js +++ b/assets/js/googlesitekit-polyfills.js @@ -26,6 +26,13 @@ async function loadPolyfills() { // errors blocks within Gutenberg built with node < v18. if ( ! Array.prototype.findLastIndex ) { Array.prototype.findLastIndex = function ( predicate, thisArg ) { + // eslint-disable-next-line no-console + console.error( + 'Array.prototype.findLastIndex polyfill applied to:', + this, + new Error().stack + ); + if ( this === null || this === undefined ) { throw new TypeError( 'Array.prototype.findLastIndex called on null or undefined'