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

[Bug]: Most pseudo-classes incorrectly purged when there is no selector before it #1282

Open
1 task done
geomydas opened this issue Oct 4, 2024 · 3 comments
Open
1 task done
Assignees
Labels

Comments

@geomydas
Copy link

geomydas commented Oct 4, 2024

Describe the bug

It removes psedo-classes without a selector before it.

/* This will be removed and purged incorrectly */

:hover { }
:not(:hover) { }
:where() {}
:where(:hover) {}


etc..

/* This will not be removed and purged incorrectly */

*:hover { }
.class:hover { }
#id:hover { }
[attribute]:hover { }
::after { }
::before { }

and etc.

It doesn't affect pseudo-elements like ::after but affects pseudo-classes. There are some exceptions which are :root but I haven't found more exceptions beyond that

The bug can be sourced from https://purgecss.com/extractors.html

Does not consider special characters such as @, :, /

To Reproduce

Already described

Expected Behavior

I was expecting them to be not removed in the CSS

Environment

OS: Linux Mint;
Package: purgecss;
Version: 6.0.0;

Add any other context about the problem here

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@geomydas geomydas added the bug label Oct 4, 2024
@geomydas geomydas changed the title [Bug]: Pseudo-elements and pseudo-classes incorrectly purged when there is no selector before it [Bug]: Pseudo-classes incorrectly purged when there is no selector before it Oct 4, 2024
@minimaldesign
Copy link

Just noticed that in the Astro integration. It is particularly problematic with things like:

:where(h1, h2, h3) {
  ...
}

@geomydas
Copy link
Author

geomydas commented Oct 5, 2024

I use a CSS library called Open Props and it uses :where(html) to contain the variables to avoid any specificty conflict and I noticed that it affected other pseudo-selectors aswell

@geomydas
Copy link
Author

geomydas commented Oct 5, 2024

Just noticed that in the Astro integration. It is particularly problematic with things like:

:where(h1, h2, h3) {
  ...
}

You can circumvent this by adding the * or global selector before it and it will be purged correctly. The only issue with this is that it may decrease performance

@Ffloriel Ffloriel self-assigned this Oct 5, 2024
@geomydas geomydas changed the title [Bug]: Pseudo-classes incorrectly purged when there is no selector before it [Bug]: Most pseudo-classes incorrectly purged when there is no selector before it Oct 23, 2024
Ffloriel added a commit that referenced this issue Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants