Description
Preconditions and environment
Magento 2.4+
PHP 8+
Steps to reproduce
Enable CSS minify
Expected result
CSS is minified properly
Actual result
Minified CSS ends up blank
Additional information
No response
Release note
Magento uses the tubalmartin/cssmin dependency to do CSS minification. In PHP 8+ this can results in blank minified CSS files, depending on the content of the CSS that is being minified. This is due to a bug in vendor/tubalmartin/cssmin/src/Minifier.php line 324:
$css = preg_replace_callback( '/(?:"(?:[^\\\\"]|\\\\.|\\\\)*")|'."(?:'(?:[^\\\\']|\\\\.|\\\\)*')/S", array($this, 'processStringsCallback'), $css );
Where this regexp is causing the backtrack limit to be reached and generating a PREG_JIT_STACK_LIMIT_ERROR. However, Minifier.php is not checking for this error so the $css variable ends up being set to null which ends up causing the deprecation message:
exception: Deprecated Functionality: preg_replace(): Passing null to parameter #3 ($subject) of type array|string
However, this is a red herring as the reason $css is null is due to this error not being caught in the earlier function call.
The bug report in tubalmartin/cssmin is tubalmartin/YUI-CSS-compressor-PHP-port#66
It seems like the options would be to fix the tubalmartin/cssmin dependency or switch Magento to a different library for CSS minification.
Current workaround is to disable CSS minification in Magento's config.
Triage and priority
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.