-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lazyload CSS background image compatibility issue with Chrome 119+ #6269
Comments
Reproduce the problem ✅I was able to reproduce the problem
Identify the root cause ✅The problem happens when an element having a 404 background image is scrolled into viewport, When this happens, we will append the style to the Scope a solution ✅I suggest that we do a check right before we append new styles to load. We will check if the image can be loaded and if not we don't append these kind of styles so as not to trigger unnecessary console errors.
Estimate the effort ✅ |
@Mai-Saad @jeawhanlee Does something has be changed on the page https://new.rocketlabsqa.ovh/ll-bgi-oct-ar/? Cause I came with Version 119.0.6045.159 (Official Build) (64-bit) on Ubuntu and I can't reproduce the issue. Ok I succeeded to reproduce it. I think first step would be to check if it is a behavior Chrome plan to fix or if it is on purpose. On the grooming itself I don't like the fact we totally hide the error to the user. There should be not multiple errors but there should not have none either. I gonna first dig a bit into Chrome to see if I can find if this is categorized as a bug for them. |
@CrochetFeve0251 We don't totally hide the error from the user with this solution, the error will only show up once as opposed to how it pops up now with every scroll. Also Irrespective of whether chrome would fix this kind of behaviour, I think we should have this kind of check just to be on the safe side to avoid lazy loading broken image links or images like |
@jeawhanlee I recreated a template to test the issue and looks like Firefox is also affected: <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style id="style">
:root{--wpr-bg-71417af1-5007-4ecf-a3bb-a534f60e8822: url('https://new.rocketlabsqa.ovh/wp-content/rocket-test-data/images/test_internal0.webp');}:root{--wpr-bg-72a04f35-a851-4bf3-814e-5cec5ada235d: url('https://new.rocketlabsqa.ovh/wp-content/rocket-test-data/image/test3.webp');}:root{--wpr-bg-e5a58dd6-df11-4dbf-bf04-3a313b24e71f: url('https://new.rocketlabsqa.ovh/wp-content/rocket-test-data/image/file_example_JPG_100kB.jpg');}:root{--wpr-bg-99f15daa-f841-4699-98c7-f13eb833031b: url('https://new.rocketlabsqa.ovh/wp-content/rocket-test-data/images/testnotExist.png');}
</style>
</head>
<body>
<div style="height:100px; width:100px; background-image: var(--wpr-bg-71417af1-5007-4ecf-a3bb-a534f60e8822);">
</div>
<div style="height:100px; width:100px; background-image: var(--wpr-bg-99f15daa-f841-4699-98c7-f13eb833031b);">
</div>
<button id="btn">Click</button>
<script type="application/javascript">
document.getElementById('btn').onclick = () => { document.getElementById('style').innerHTML += ":root{--wpr-bg-71417af1-5007-4ecf-a3bb-a534f60e8822: url('https://new.rocketlabsqa.ovh/wp-content/rocket-test-data/images/test_internal0.webp');}"; }
</script>
</body>
</html> Seems like the issue is coming from the fact we modify the same style tag. (Looks like I am wrong all the style tags are reloaded when we add some content in one of them Q.q) |
@CrochetFeve0251 Yeah, I understand the costs that might come with using a regex here but it should be as basic as getting the url from a var like this:
|
Scope a solution ✅First we will have to expose the data we need in the tag for that we will have to change the logic in MappingFormatter:
$variable_placeholder = $datum['selector'] . '{' . $placeholder . ': ' . $url . ';}';
$formatted_urls[] = [
'selector' => $selector,
'url' => $datum['url'] Then we will now use the Image object for this kind of check and use the pair.url as img.src then we only append the style when that image can be loaded. img.onload = () => {
styleElement.innerHTML += pair.style;
} We will also have to change the tag to prevent the reload from the styles on each time. For that inside TagGenerator we will have transform the style tag to a div one: $loaded_tag = "<div id=\"wpr-lazyload-bg\"></div><style id=\"wpr-lazyload-bg-exclusion\">$loaded_content</style>"; Finally inside the script, we change the logic to add a style on each time: styleElement.innerHTML += `<style>${pair.style}</style>`; Estimate the effort ✅Effort |
Looks good to me. |
Before submitting an issue please check that you’ve completed the following steps:
Describe the bug
Multiple request is sent to the same image using a specific page template https://new.rocketlabsqa.ovh/ll-bgi-oct-ar/
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Single request sent to
testnotExist.png
andfile_example_TIFF_1MB.tiff
Console error for the 404 testnotExist happens only once as it was used once in the page
Screenshots
Additional context
Add any other context about the problem here.
Acceptance Criteria (for WP Media team use only)
Clear instructions for developers, to be added before the grooming
The text was updated successfully, but these errors were encountered: