From adc4834b426c5bdea311845f7249598b3d3aac41 Mon Sep 17 00:00:00 2001 From: Opeyemi Ibrahim Date: Tue, 8 Oct 2024 12:11:45 +0100 Subject: [PATCH] fixed lcp background image :bug: :closes: wp-media/wp-rocket#6728 --- src/BeaconLcp.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/BeaconLcp.js b/src/BeaconLcp.js index a087b96..5dc5ab1 100644 --- a/src/BeaconLcp.js +++ b/src/BeaconLcp.js @@ -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") { @@ -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.");