Skip to content

Rewrite Purger #46

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

Merged
merged 1 commit into from
Aug 18, 2021
Merged

Rewrite Purger #46

merged 1 commit into from
Aug 18, 2021

Conversation

jonathanhefner
Copy link
Member

This rewrite accomplishes a few things:

  • Fixes group-hover classes are not removed #20. Closes Add test for group-hover classes #22.

  • Purges selectors that aren't on the same line as their block brace:

    Before

    .sm\:aspect-w-1,
    /* ... */
    .sm\:aspect-w-15 > *,
    @media (prefers-color-scheme: dark) {
    }
  • Purges empty "at rule" blocks (e.g. empty @media blocks).

  • Purges comments, except within property values.

  • Adds support for nested selector blocks, to prepare for the future. For example, Tailwind has many .group:hover .group-hover\:X rules that could be written as .group:hover { .group-hover\:X { ... } }.

  • Improves performance:

    Before

    $ bin/test -n test_basic_purge
    
    Finished in 2.307380s, 0.4334 runs/s, 3.0337 assertions/s.
    1 runs, 7 assertions, 0 failures, 0 errors, 0 skips

    After

    $ bin/test -n test_basic_purge
    
    Finished in 1.824162s, 0.5482 runs/s, 3.8374 assertions/s.
    1 runs, 7 assertions, 0 failures, 0 errors, 0 skips

For reference: the purged CSS from the test fixtures was 35,099 bytes before this change, and 22,141 bytes after this change.

This rewrite accomplishes a few things:

* Fixes rails#20.  Closes rails#22.

* Purges selectors that aren't on the same line as their block brace:

    **Before**

    ```css
    .sm\:aspect-w-1,
    /* ... */
    .sm\:aspect-w-15 > *,
    @media (prefers-color-scheme: dark) {
    }
    ```

* Purges empty "at rule" blocks (e.g. empty `@media` blocks).

* Purges comments, except within property values.

* Adds support for nested selector blocks, to prepare for the future.
  For example, Tailwind has many `.group:hover .group-hover\:X` rules
  that could be written as `.group:hover { .group-hover\:X { ... } }`.

* Improves performance:

    **Before**

    ```bash
    $ bin/test -n test_basic_purge

    Finished in 2.307380s, 0.4334 runs/s, 3.0337 assertions/s.
    1 runs, 7 assertions, 0 failures, 0 errors, 0 skips
    ```

    **After**

    ```bash
    $ bin/test -n test_basic_purge

    Finished in 1.824162s, 0.5482 runs/s, 3.8374 assertions/s.
    1 runs, 7 assertions, 0 failures, 0 errors, 0 skips
    ```
@henrikbjorn
Copy link

@dhh What is the process for getting this merged and released?

Have this gem been abandoned?

@dhh dhh merged commit c3cb2c1 into rails:main Aug 18, 2021
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

Successfully merging this pull request may close these issues.

group-hover classes are not removed
3 participants