magento2
magento2 copied to clipboard
CSS minifiying sometimes results in blank CSS file due to PREG_JIT_STACK_LIMIT_ERROR in tubalmartin/cssmin
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 https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port/issues/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.
- [X] 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”.
Hi @nahall. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:
-
@magento give me 2.4-develop instance
- upcoming 2.4.x release - For more details, review the Magento Contributor Assistant documentation.
- Add a comment to assign the issue:
@magento I am working on this
- To learn more about issue processing workflow, refer to the Code Contributions.
Join Magento Community Engineering Slack and ask your questions in #github channel. :warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting. :clock10: You can find the schedule on the Magento Community Calendar page. :telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.
Hi @engcom-Dash. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
-
- Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
-
- Verify that issue has a meaningful description and provides enough information to reproduce the issue.
-
- Add
Area: XXXXX
label to the ticket, indicating the functional areas it may be related to.
- Add
-
- Verify that the issue is reproducible on
2.4-develop
branchDetails
- Add the comment@magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on2.4-develop
branch, please, add the labelReproduced on 2.4.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
- Verify that the issue is reproducible on
- Join Magento Community Engineering Slack and ask your questions in #github channel.
@magento give me 2.4-develop instance
Hi @engcom-Dash. Thank you for your request. I'm working on Magento instance for you.
Hi @engcom-Dash, here is your Magento Instance: https://34dd16ce2d6b21223b86a148b078666d.instances-prod.magento-community.engineering Admin access: https://34dd16ce2d6b21223b86a148b078666d.instances-prod.magento-community.engineering/admin_5b3b Login: e3c315f8 Password: 30a9a585e723
Hi @nahall
Thanks for reporting and collaboration.
Verified the issue on magento develop instance and issue is not reproducible.
We have followed the below steps to reproduce:
- Log in to your Magento 2 admin panel 2.Navigate to Stores>Configuration 3.Go into the advanced tab and then the developer tab under configuration. 4.Go to CSS settings and set the minify option to ‘Yes'
The CSS is minified. properly. Please refer the attached screenshot.
This does not fail with the stock Magento CSS but only in certain cases.
Since the problematic regexp in the CSS minifier is:
$css = preg_replace_callback(
'/(?:"(?:[^\\\\"]|\\\\.|\\\\)*")|'."(?:'(?:[^\\\\']|\\\\.|\\\\)*')/S",
array($this, 'processStringsCallback'),
$css
);
It seems likely that the CSS needs to contain a number of quotation marks in order to encounter the problem.
Hi @nahall
Thanks for reporting and collaboration.
Can you please check if you are using any third party modules and try to reproduce the issue by disabling one by one. Please let us know if you are still facing the issue.
Thanks
Hi @nahall
We have noticed that this issue has not been updated since long time. Hence we assume that this issue is fixed now, so we are closing it. Please feel to raise a fresh ticket or reopen this ticket if you need more assistance on this.
Thanks.
The bug is still happening. It is not because of third party modules but rather in certain cases of CSS.
Here is workaround: https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port/issues/66#issuecomment-1868359514
Why is this ticket closed? This is happening today.