Skip to content

Commit

Permalink
Merge pull request #1760 from WordPress/fix/erroneous-initiator-type
Browse files Browse the repository at this point in the history
Remove erroneous check for resource initiator type when considering whether to submit LCP background image
  • Loading branch information
westonruter authored Dec 19, 2024
2 parents c446d8c + eee6bf2 commit d0299a3
Showing 1 changed file with 0 additions and 48 deletions.
48 changes: 0 additions & 48 deletions plugins/image-prioritizer/detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,6 @@ function log( ...message ) {
console.log( consoleLogPrefix, ...message );
}

/**
* Logs a warning.
*
* @since 0.3.0
*
* @param {...*} message
*/
function warn( ...message ) {
// eslint-disable-next-line no-console
console.warn( consoleLogPrefix, ...message );
}

/**
* Initializes extension.
*
Expand All @@ -77,27 +65,6 @@ export async function initialize( { isDebug, onLCP } ) {
);
}

/**
* Gets the performance resource entry for a given URL.
*
* @since 0.3.0
*
* @param {string} url - Resource URL.
* @return {PerformanceResourceTiming|null} Resource entry or null.
*/
function getPerformanceResourceByURL( url ) {
const entries =
/** @type PerformanceResourceTiming[] */ performance.getEntriesByType(
'resource'
);
for ( const entry of entries ) {
if ( entry.name === url ) {
return entry;
}
}
return null;
}

/**
* Handles a new LCP metric being reported.
*
Expand Down Expand Up @@ -129,21 +96,6 @@ function handleLCPMetric( metric, isDebug ) {
continue;
}

// Now only consider proceeding with the URL if its loading was initiated with stylesheet or preload link.
const resourceEntry = getPerformanceResourceByURL( entry.url );
if (
! resourceEntry ||
! [ 'css', 'link' ].includes( resourceEntry.initiatorType )
) {
if ( isDebug ) {
warn(
`Skipped considering URL (${ entry.url }) due to unexpected performance resource timing entry:`,
resourceEntry
);
}
return;
}

// Skip URLs that are excessively long. This is the maxLength defined in image_prioritizer_add_element_item_schema_properties().
if ( entry.url.length > 500 ) {
if ( isDebug ) {
Expand Down

0 comments on commit d0299a3

Please sign in to comment.