Skip to content

Commit

Permalink
fixed lcp background image 🐛 :closes: wp-media/wp-rocket#6728
Browse files Browse the repository at this point in the history
  • Loading branch information
Khadreal committed Oct 8, 2024
1 parent 78ca211 commit adc4834
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/BeaconLcp.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ class BeaconLcp {
element_info.bg_set = matches.map(m => m[1] ? { src: m[1].trim() } : {});
}

if (element_info.bg_set.length <= 0) {
return null;
}

if (element_info.bg_set.length > 0) {
element_info.src = element_info.bg_set[0].src;
if (element_info.type === "bg-img-set") {
Expand All @@ -165,7 +169,9 @@ class BeaconLcp {
}

_initWithFirstElementWithInfo(elements) {
const firstElementWithInfo = elements.find(item => item.elementInfo !== null);
const firstElementWithInfo = elements.find(item => {
return item.elementInfo !== null && (item.elementInfo.src || item.elementInfo.srcset);
});

if (!firstElementWithInfo) {
this.logger.logMessage("No LCP candidate found.");
Expand Down

0 comments on commit adc4834

Please sign in to comment.