Skip to content
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 Images is not working with multiple identical selectors. #7172

Open
johan-las opened this issue Dec 6, 2024 · 0 comments

Comments

@johan-las
Copy link

Describe the bug
If multiple instances of the same selector exist, it selects the first instance without verifying whether it contains a background image.

As a result, the background image is not replaced with the variable, causing the image to load directly on page load instead of being lazy-loaded.

To Reproduce
Steps to reproduce the behavior:

  1. Create a page with background images.
  2. Create multiple instances of the same selector before the one with the background image, as shown in the example below.
.section_0 { height: 1000px; }
.section_0 { font-size:13px; }
.section_0 { background-image: url('https://domain.com/image.jpg'); }
  1. Verify the CSS of the element, it's not replaced by the variable.

Expected behavior
It should detect the block containing the background image while ignoring the others.

Additional context

The issue is tracked in /inc/Engine/Media/Lazyload/CSS/Subscriber.php, specifically in the generate_content() function.

Printing the variable $url_tags show that the block is not the correct one.:

Array
(
    [0] => Array
        (
            [selector] => .kadence-column5373_1cb77f-f6 > .kt-inside-inner-col
            [url] => https://xxxx/wp-content/uploads/2024/03/focus-on-improving.webp
            [original] => url('https://xxxx/wp-content/uploads/2024/03/focus-on-improving.webp')
            [block] => .kadence-column5373_1cb77f-f6 > .kt-inside-inner-col{column-gap:var(--global-kb-gap-sm, 1rem);}
            [hash] => 9bd2d540-fe97-45c6-a56e-5e6d8197b61b
        )

)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant