-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Downgrade the Node.js LESS compiler from v4 to v3 to avoid less compilation problems #38109
Downgrade the Node.js LESS compiler from v4 to v3 to avoid less compilation problems #38109
Conversation
Hi @serhii-chernenko. Thank you for your contribution! Add the comment under your pull request to deploy test or vanilla Magento instance:
❗ Automated tests can be triggered manually with an appropriate comment:
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
Hi @serhii-chernenko, I'm not sure exact reason why it was updated, but guess it was due to security reasons and/or compatibility with newer nodejs versions. From the fix perspective your fix is fully valid and correct, while from security perspective, having latest version is more secure. So I would prefer fixing the reasoning of this regression rather than downgrading dependencies. Will you be able to check that? |
hi @ihor-sviziev, You're right about up-to-dated packages when they used in production or it's an application that built on NPM packages. While the magento 2 uses grunt only for local development, it's not really matter IMHO. There's just a funny findings: I won't have time to investigate this issue soon. Probably someone else could be able to investigate this issue. If not, you can leave this PR opened, and I'll have a look at this later when I'll have time. |
@serhii-chernenko: wasn't this already fixed in #28415? This is to be released in Magento 2.4.7, I agree that it took a very long time before it got picked up, but it's what it is I'm afraid. However, your observation around
|
The unit error can be fixed by adding some parenthesis, like this: diff --git a/lib/web/css/source/lib/variables/_typography.less b/lib/web/css/source/lib/variables/_typography.less
index e357b6969db..177b061323b 100644
--- a/lib/web/css/source/lib/variables/_typography.less
+++ b/lib/web/css/source/lib/variables/_typography.less
@@ -29,10 +29,10 @@
@font-size-ratio__base: 1.4; // Defines ratio of the root font-size to the base font-size
@font-size-unit: rem; // The unit to which most typography values will be converted by default
-@font-size-unit-ratio: unit(@root__font-size * 16/100); // Ratio of the root font-size to the font-size unit
+@font-size-unit-ratio: unit((@root__font-size * 16/100)); // Ratio of the root font-size to the font-size unit
@font-size-unit-convert: true; // Controls whether font-size values are converted to the specified font-size unit
-@font-size__base: unit(@font-size-unit-ratio * @font-size-ratio__base, px); // Base font size value in <b>px</b>
+@font-size__base: unit((@font-size-unit-ratio * @font-size-ratio__base), px); // Base font size value in <b>px</b>
@font-size__xl: ceil(1.5 * @font-size__base); // 21px
@font-size__l: ceil(1.25 * @font-size__base); // 18px
@font-size__s: ceil(.85 * @font-size__base); // 12px However, after this another less compilation error pops up:
But the problems keep coming, after disabling that one line quickly as a test, yet another error comes up:
So it sounds like the upgrade from less v3 to v4 from a1bbede#diff-0b861b52f90917125f2829df6f171d1248cc83df2a15ff7d7dc7b6f59048e9b1 was not properly tested. Maybe we should revert this partially? Other than this, we really need some automated tests to verify the nodejs parts of Magento (like compiling less code) works as it should work, I have the feeling we don't have automated tests for this, adding these could prevent errors like this in the future ... For completion's sake, found it in some comment in the v4.0.0 pull request of less (there is no changelog, no upgrade guide, so this is a bit difficult to deal with):
If I search through magento's less codebase, I find a lot of divisions that aren't in parenthesis, so those will most likely also start causing issues. So downgrading to less v3 sounds like the best plan here for now. Other opinions? @glo71317: what do you think, since you were involved in AC-8132? Also please in the future always test the nodejs / grunt workflow after updating nodejs dependencies. Thanks! |
@hostep we have upgraded Less js library to the latest version (4.1.3) that time and tested by running tests i.e., grunt spec:luma. Tests was successful. However, it seems like this issue would have been existed previously as well before the recent upgrade. We will look into the below less compilation unit error and will update accordingly.
|
The following downgrades make less compilation with grunt work without errors: diff --git a/package.json.sample b/package.json.sample
index 9fbde04e8a7..faa6cb7ff47 100644
--- a/package.json.sample
+++ b/package.json.sample
@@ -18,7 +18,7 @@
"grunt-contrib-cssmin": "~4.0.0",
"grunt-contrib-imagemin": "~4.0.0",
"grunt-contrib-jasmine": "~4.0.0",
- "grunt-contrib-less": "~3.0.0",
+ "grunt-contrib-less": "~2.1.0",
"grunt-contrib-watch": "~1.1.0",
"grunt-eslint": "~24.2.0",
"grunt-exec": "~3.0.0",
@@ -27,7 +27,7 @@
"grunt-template-jasmine-requirejs": "~0.2.3",
"grunt-text-replace": "~0.4.0",
"imagemin-svgo": "~9.0.0",
- "less": "4.1.3",
+ "less": "~3.13.1",
"load-grunt-config": "~4.0.1",
"morgan": "~1.10.0",
"node-minify": "~3.6.0", @serhii-chernenko: I would suggest you update your PR in this way. Maybe also change the title of the PR (as the sourcemap generation was already fixed in an earlier PR like I already mentioned) Steps to reproduce: # to remove any traces of old install
$ rm -R node_modules/ package-lock.json
# make changes to `package.json` file (if it doesn't exist, copy it from `package.json.sample`)
# install nodejs packages
$ npm install
# execute grunt commands (will only work when you've copied `Gruntfile.js.sample` to `Gruntfile.js`)
$ grunt clean:luma && grunt exec:luma && grunt less:luma |
@glo17680 can we submit a PR for downgrading |
@hostep but what's the difference with the LTS version
source maps aren't working there with the same versions:
|
@serhii-chernenko, please re-read my earlier comment:
So issue has been fixed but hasn't been released yet. It will be released in Magento 2.4.7. But if you want a quick fix now, then apply the following changes using a patch: https://github.com/magento/magento2/pull/28415/files |
@hostep oh, I see. sorry, I didn't get that the change was only in 2.4.7. yeah, the package downgrading has to be a solution for 2.4.7 then |
Great, @serhii-chernenko, do you want to update your PR with my suggested downgrades? Or should we open a new one? |
grunt-contrib-less and less packages downgraded to make source maps working for magento 2.4.7+
@hostep done |
@serhii-chernenko and the last thing - pls sign the Adobe CLA |
@magento run all tests |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues. |
@ihor-sviziev signed |
I still think we should change the title & description & manual testing steps of this PR to avoid confusion for anyone that runs against this ticket. The PR is not fixing sourcemaps (because it was already fixed by another PR earlier), it just downgrades the nodejs less compiler from v4 to v3 to avoid less compilation problems. |
@hostep @ihor-sviziev done |
@glo17680: I just tried out your changes from 320182b & fe17ac2 and there are still a ton of problems. It feels like those changes haven't been tested by reviewing the frontend rendering... I just did that and compared the results from grunt less compilation using less.js 3.13.1 to 4.2.0 If I take a look at the differences of the resulting css that gets generated between v3 and v4 I'm seeing about 187 changes of which most have to do with calculating sizes, some extracts: diff -urwN v3/styles-l.css v4/styles-l.css
--- v3/styles-l.css 2024-01-03 20:48:55
+++ v4/styles-l.css 2024-01-03 20:45:28
@@ -304,7 +304,7 @@
padding: 0 12px 0 0;
box-sizing: border-box;
display: inline-block;
- width: 50%;
+ width: 100% / 2;
vertical-align: top;
}
.abs-form-field-column-2 .fieldset .field + .fieldset,
@@ -335,7 +335,7 @@
width: 100%;
}
.abs-form-field-revert-column-1 {
- width: 100%;
+ width: 100% / 1;
}
.abs-forms-general-desktop,
.form.search.advanced,
@@ -378,7 +378,7 @@
.box-information .box-content,
.block-balance-giftcard .block-content,
.block-reviews-dashboard .product-name {
- font-size: 1.6rem;
+ font-size: 16rem / 10;
}
.abs-account-table-margin-desktop,
.table-wrapper.balance-history,
@@ -506,7 +506,7 @@
.abs-discount-block-desktop .block > .title strong,
.paypal-review-discount .block > .title strong,
.cart-discount .block > .title strong {
- font-size: 1.6rem;
+ font-size: 16rem / 10;
}
.abs-discount-block-desktop .block .content,
.paypal-review-discount .block .content,
... The resulting css with v4 is considered invalid by google chrome, see all these exclamation marks: So I would very strongly recommend we downgrade again to v3, or make a follow up fix before Magento 2.4.7 gets released that fixes all those incorrect calculations being done now in v4 of the less.js compiler ... Also, I would strongly recommend you figure out a way to properly test these kind of changes for the future, so next time you want to attempt a less.js library upgrade, you'll immediately can see the results and can properly compare the results with how they were before the upgrade. |
@glo17680: I've spend the entire afternoon today on #38335, but I'm running out of time and energy. The grunt compilation I've tested and it fixes the issue I discussed before. The normal |
Hello @serhii-chernenko |
@andrewbess : can we have a conclusion first here before more work is put into this? Should we downgrade less.js back to v3, or will we continue with fixing the less files themselves, so they are compatible both with v3 and v4? |
Hello @hostep |
Hi @andrewbess @hostep @serhii-chernenko @ihor-sviziev Thanks to all for contributing and highlighting the issue. Surely we will take a look on this on priority. Thanks, |
Hello Guys, We had discussed and agreed we will not downgrade v4 to v3. We will continue working with This PR |
So, based on #38109 (comment), I'm closing this pull request in favor to #38335. |
Description (*)
I don't even believe that no one didn't comment this PR #31618 during 2 years. Do you know that styles sourcemaps are broken since updating this package in
package.json
.each time it has to be fixed for a new project.
grunt-contrib-less
1.4.1
:grunt-contrib-less
~2.1.0
:you ask for self-checking, tests running, screenshots, but don't check the first development steps when you update something. that's weird.
video example that includes the fix (use subtitles) with timecode:
https://youtu.be/NEKvPRTW9mM?si=2f_ZXV-WNR8IyN9N&t=699
that's even funny that in M2.4.7 beta this package is updated to
~3.0.0
203f415
but it couldn't be compiled because of error:
Related Pull Requests
Manual testing scenarios (*)
grunt clean:theme && exec:theme && less:theme
1.4.1
from~2.1.0
npm i
Contribution checklist (*)