Problem/Motivation

We noticed a compatibility issue with AdvAgg CSS minification and the new Drupal core admin theme Claro. We had an issue open for that here: #3056046: SVG Problem with AdvAgg aggregation but it was closed because it was actually a problem in a dependency of AdvAgg which has been resolved in more recent releases: https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port/issues/25.

Proposed resolution

I guess we could either update YUI Compressor to its most recent version, or just update to the most recent patch release of the current major release.

Remaining tasks

  1. Decide which version Yui Compressor should be updated: https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port/releases

Comments

lauriii created an issue. See original summary.

jwilson3’s picture

This SVG compression problem from the YUI Compressor not only affects AdvAgg + Claro theme, but also AdvAgg + Bootstrap 4 related themes, such as Radix because Bootstrap 4 inlines the SVGs for several components like the next/previous icons for carousel component, and the radio/checkbox for their .custom-* form components.

The workaround for me has been to leverage sass's str-replace() mixin to manually url encode all space characters with '%20'.

in src/sass/base/_variables.scss:

$custom-checkbox-indicator-icon-checked: str-replace(str-replace(url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='#{$custom-control-indicator-checked-color}' d='M6.564.75l-3.59 3.612-1.538-1.55L0 4.26 2.974 7.25 8 2.193z'/%3e%3c/svg%3e"), "#", "%23"), " ", "%20");
$custom-checkbox-indicator-icon-indeterminate: str-replace(str-replace(url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 4 4'%3e%3cpath stroke='#{$custom-checkbox-indicator-indeterminate-color}' d='M0 2h4'/%3e%3c/svg%3e"), "#", "%23"), " ", "%20") !default;
$custom-radio-indicator-icon-checked:           str-replace(str-replace(url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='#{$custom-control-indicator-checked-color}'/%3e%3c/svg%3e"), "#", "%23"), " ", "%20") !default;
$custom-select-indicator:  str-replace(str-replace(url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 4 5'%3e%3cpath fill='#{$custom-select-indicator-color}' d='M2 0L0 2h4zm0 5L0 3h4z'/%3e%3c/svg%3e"), "#", "%23"), " ", "%20") !default;
$form-feedback-icon-valid: str-replace(str-replace(url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='#{$form-feedback-icon-valid-color}' d='M2.3 6.73L.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1z'/%3e%3c/svg%3e"), "#", "%23"), " ", "%20");
$form-feedback-icon-invalid: str-replace(str-replace(url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='#{$form-feedback-icon-invalid-color}' viewBox='-2 -2 7 7'%3e%3cpath stroke='#{$form-feedback-icon-invalid-color}' d='M0 0l3 3m0-3L0 3'/%3e%3ccircle r='.5'/%3e%3ccircle cx='3' r='.5'/%3e%3ccircle cy='3' r='.5'/%3e%3ccircle cx='3' cy='3' r='.5'/%3e%3c/svg%3E"), "#", "%23"), " ", "%20");
$navbar-dark-toggler-icon-bg: str-replace(str-replace(url("data:image/svg+xml,%3csvg viewBox='0 0 30 30' xmlns='http://www.w3.org/2000/svg'%3e%3cpath stroke='#{$navbar-dark-color}' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e"), "#", "%23"), " ", "%20");
$navbar-light-toggler-icon-bg: str-replace(str-replace(url("data:image/svg+xml,%3csvg viewBox='0 0 30 30' xmlns='http://www.w3.org/2000/svg'%3e%3cpath stroke='#{$navbar-light-color}' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e"), "#", "%23"), " ", "%20");
$carousel-control-prev-icon-bg: str-replace(str-replace(url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='#{$carousel-control-color}' viewBox='0 0 8 8'%3e%3cpath d='M5.25 0l-4 4 4 4 1.5-1.5-2.5-2.5 2.5-2.5-1.5-1.5z'/%3e%3c/svg%3e"), "#", "%23"), " ", "%20");
$carousel-control-next-icon-bg: str-replace(str-replace(url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='#{$carousel-control-color}' viewBox='0 0 8 8'%3e%3cpath d='M2.75 0l-1.5 1.5 2.5 2.5-2.5 2.5 1.5 1.5 4-4-4-4z'/%3e%3c/svg%3e"), "#", "%23"), " ", "%20");
jwilson3’s picture

StatusFileSize
new874 bytes

A second perhaps better workaround is the following patch, which also requires running composer require tubalmartin/cssmin in your site.

This will work until a more complete patch would remove and or update CSSMin class from the module codebase and add a dependency in this module's composer.json, or instructions in the module's README.

jwilson3’s picture

Status: Active » Needs work

Marking it needs work, because the patch in #3 does nothing to clean up the old outdated CSSMin class bundled with the module in advagg/advagg_css_minify/yui/CSSMin.inc.

joelpittet’s picture

Status: Needs work » Needs review
StatusFileSize
new33.38 KB

@jwilson3 I'm not sure the answer here but could we add this to the composer.json as a dependency and if so, will this require we version bump and include non-composer instructions?

I feel it would be "easy" to update the code in place but maybe not "right". Anyways this patch is just riffing on the direction you were going with composer.

joelpittet’s picture

Added to the main composer.json because there is no way to do optional third-party dependencies, discussed with @mixologic

Status: Needs review » Needs work

The last submitted patch, 5: 3127422-5-composer-cssmin-dependency.patch, failed testing. View results

joelpittet’s picture

Status: Needs work » Needs review
StatusFileSize
new34.51 KB

If we want a quick-fix, I don't mind dumping the class in that file and calling it a day... just say the word maintainers.

Quick change to the test.

Status: Needs review » Needs work

The last submitted patch, 8: 3127422-8-composer-cssmin-dependency.patch, failed testing. View results

joelpittet’s picture

Status: Needs work » Needs review
StatusFileSize
new34.35 KB

My editor added a line break at the end of the file.

agoradesign’s picture

works for me :)

jwilson3’s picture

@joelpittet, thanks for picking up the ball and running with it!

I like that you also updated the comment_hacks css file. It made me wonder if we should actually add a test for something like the inline SVG data uri as a test case in a CSS file? Provide a "-tests-only" patch and watch it fail. Maybe this is going too far for a contrib module, and since I'm not the maintainer, it's just a suggestion.

If we want a quick-fix, I don't mind dumping the class in that file and calling it a day... just say the word maintainers.

Again, not the maintainer, but I cannot see how a maintainer would consciously make the decision to do something like and perpetuate more work for themselves to keep the library up-to-date long into the future, rather than just adding the composer dependency like your patches do, which is super easy to update in the future.

jwilson3’s picture

Status: Needs review » Reviewed & tested by the community

Anyone feel free to set back to NW if they feel strongly about implementing tests. I'm good with it as is.

The last submitted patch, 3: advagg-update-cssmin-3127422-3.patch, failed testing. View results

thalles’s picture

This looks good to me!
I think good add composer dependencies.

  • thalles committed f45217b on 8.x-4.x authored by joelpittet
    Issue #3127422 by joelpittet, jwilson3: Update YUI Compressor to a more...
thalles’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

playful’s picture

I tried #10 on 8.4.1 using D8.9.7 and got a WSOD with this error:

Error: Class 'tubalmartin\CssMin\Minifier' not found in Drupal\advagg_css_minify\Asset\CssMinifier->minifyCssMin() (line 110 of /home/forge/mysite.org/web/modules/contrib/advagg/advagg_css_minify/src/Asset/CssMinifier.php)

I'm still unable to use the YUI compressor since it doesn't work with Radix. Help appreciated!

rar9’s picture

any update for radix?

klemendev’s picture