-
Notifications
You must be signed in to change notification settings - Fork 225
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 Background CSS Images pseudo classes handling improvement #6132
Comments
A possible fix is the following solution:
|
For that we gonna change the logic inside the protected function remove_pseudo_classes( string $selector ): string {
$selectors = split($selector, ',');
$original_pseudo_elements = [
':before',
':after',
':first-line',
':first-letter',
];
/**
* Pseudo elements to remove from lazyload CSS selector.
*
* @param string[] Pseudo elements to remove.
*/
$pseudo_elements_to_remove = apply_filters( 'rocket_lazyload_css_ignored_pseudo_elements', $original_pseudo_elements );
if ( ! is_array( $original_pseudo_elements ) ) {
$pseudo_elements_to_remove = $original_pseudo_elements;
}
$selectors = array_map(function($selector) use ($pseudo_elements_to_remove) {
foreach ( $pseudo_elements_to_remove as $element ) {
$selector = str_replace( $element, '', $selector );
}
if(in_array(substr($selector, -1), ['&','~','+'']) {
$selector .= '*';
}
return $selector;
}, $selectors);
$selector = implode($selectors, ',');
if ( ! $selector ) {
return 'body';
}
return (string) $selector;
} |
I believe this needs R&D. @CrochetFeve0251 the code u mentioned did u test it? or it's just an idea? I believe it should work. |
It is just an idea to illustrate the logic |
I agree taking some time to do test with the solution and make sure it works would be the best |
@CrochetFeve0251 We could list all variations (single and double colons) in original_pseudo_elements but it sounds a bit heavy and we could get funky results based on the order of the elements in the array ('::after', ':after') will not behave like (':after','::after')
|
@Tabrisrp is right, it should be easy to write this as a script an run it on some CSS files to confirm the behavior. |
@MathieuLamiot The 'problem' would happen if |
Concerning the duplicated selector that can be handled quite easily using Concerning the Concerning the script I really dont see the benefit from it as tests will force us to readapt any logic not valid. |
Ah ok, then
We need to handle double colon first. |
Before submitting an issue please check that you’ve completed the following steps:
Describe the bug
LazyLoad Background CSS Images is not handling correctly CSS background images that are added to specific selectors with pseudo classes:
-
:after
-
.class>:after
-
.class&:after
-
.class~:after
Single colon syntax is possible only for the following pseudo-elements:
::before
,::after
,::first-line
, and::first-letter
and they all should be covered. We should also cover single colon syntax for the following ones:
:hover
:focus
:active
:visited
:focus-within
:focus-visible
For the double colon we should cover all of them with those special characters added just before:
-
.class>::after
-
.class&::after
-
.class~::after
The root cause here is that
.class>:after
is a correct syntax while.class>
is not. Our JS code is not able to find the pseudo classes and when removing them it reports wrong markup.class>
.To Reproduce
Steps to reproduce the behavior:
Expected behavior
We should cover those scenarios, it might need a bit of r&d to find the best solution
Acceptance Criteria (for WP Media team use only)
.class::after
without regressionThe text was updated successfully, but these errors were encountered: