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

CSS minifiying sometimes results in blank CSS file due to PREG_JIT_STACK_LIMIT_ERROR in tubalmartin/cssmin #38313

Closed
1 of 5 tasks
nahall opened this issue Dec 23, 2023 · 12 comments
Assignees
Labels
Issue: needs update Additional information is require, waiting for response Reported on 2.4.x Indicates original Magento version for the Issue report.

Comments

@nahall
Copy link

nahall commented Dec 23, 2023

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”.
Copy link

m2-assistant bot commented Dec 23, 2023

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:


Join Magento Community Engineering Slack and ask your questions in #github channel.
⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
🕙 You can find the schedule on the Magento Community Calendar page.
📞 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.

@engcom-Bravo engcom-Bravo added the Reported on 2.4.x Indicates original Magento version for the Issue report. label Dec 24, 2023
@engcom-Dash engcom-Dash self-assigned this Dec 28, 2023
Copy link

m2-assistant bot commented Dec 28, 2023

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: 👇

    1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    1. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
    1. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
    1. Verify that the issue is reproducible on 2.4-develop branch
      Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
      - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced 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!

@engcom-Dash
Copy link
Contributor

@magento give me 2.4-develop instance

Copy link

Hi @engcom-Dash. Thank you for your request. I'm working on Magento instance for you.

Copy link

@engcom-Dash
Copy link
Contributor

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:

  1. 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.
cssminified

@engcom-Dash engcom-Dash added the Issue: needs update Additional information is require, waiting for response label Jan 3, 2024
@nahall
Copy link
Author

nahall commented Jan 3, 2024

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.

@engcom-Dash
Copy link
Contributor

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

@engcom-Dash
Copy link
Contributor

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.

@nahall
Copy link
Author

nahall commented Jan 24, 2024

The bug is still happening. It is not because of third party modules but rather in certain cases of CSS.

@VladyslavSikailo
Copy link
Contributor

VladyslavSikailo commented Mar 26, 2024

Here is workaround: tubalmartin/YUI-CSS-compressor-PHP-port#66 (comment)

@Ryangr0
Copy link

Ryangr0 commented Jun 20, 2024

Why is this ticket closed? This is happening today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: needs update Additional information is require, waiting for response Reported on 2.4.x Indicates original Magento version for the Issue report.
Projects
None yet
Development

No branches or pull requests

5 participants