Skip to content
Open
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
37 changes: 37 additions & 0 deletions assets/js/googlesitekit-polyfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,43 @@
__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 ) {
// 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'
);
}
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' );
}
Expand Down
6 changes: 0 additions & 6 deletions tests/e2e/config/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
];

/**
Expand Down
Loading