Skip to content

Commit

Permalink
Closes #6634: Preload tag has incorrect markup if LCP element has at …
Browse files Browse the repository at this point in the history
…least 2 background-images among pseudo-elements (#6664)

Co-authored-by: WordPressFan <ahmed@wp-media.me>
Co-authored-by: Opeyemi Ibrahim <opeyemi.khadri@gmail.com>
Co-authored-by: Mathieu Lamiot <mathieu.lamiot@free.fr>
  • Loading branch information
4 people committed Jun 6, 2024
1 parent 78395ea commit 4dd69dd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions assets/js/lcp-beacon.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class RocketLcpBeacon {
current_src: ""
};

const css_bg_url_rgx = /url\(\s*?['"]?\s*?(\S+?)\s*?["']?\s*?\)\s*?([a-zA-Z0-9\s]*[x|dpcm|dpi|dppx]?)/ig;
const css_bg_url_rgx = /url\(\s*?['"]?\s*?(.+?)\s*?["']?\s*?\)/ig;

if (nodeName === "img" && element.srcset) {
element_info.type = "img-srcset";
Expand Down Expand Up @@ -186,9 +186,12 @@ class RocketLcpBeacon {
computed_style.getPropertyValue("background-image"),
getComputedStyle(element, ":after").getPropertyValue("background-image"),
getComputedStyle(element, ":before").getPropertyValue("background-image")
];
].filter(prop => prop !== "none");

const full_bg_prop = bg_props.filter(prop => prop !== "none").join("");
if (bg_props.length === 0) {
return null;
}
const full_bg_prop = bg_props[0];
element_info.type = "bg-img";
if (full_bg_prop.includes("image-set(")) {
element_info.type = "bg-img-set";
Expand Down
2 changes: 1 addition & 1 deletion assets/js/lcp-beacon.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4dd69dd

Please sign in to comment.