-
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
[Backport] Magento UI - Cleanup of undefined mixins parameters and usage of "leaking" variables scope #17097
[Backport] Magento UI - Cleanup of undefined mixins parameters and usage of "leaking" variables scope #17097
Conversation
Hi @mageprince. Thank you for your contribution
For more details, please, review the Magento Contributor Assistant documentation |
…meters and usage of "leaking" variables scope #17097
Hi @mageprince. Thank you for your contribution. Please, consider to port this solution to 2.3 release line. |
@mageprince @Igloczek You should not just simply like that remove mixin methods from code while those methods are still called in other files and are not removed as well. It is regarding this commit. I updated my Magento2 to version 2.2.6 and grunt started to throw errors and could not finish the process. Here is the aborting error messages:
|
@tomijs this documentation is unmaintained, that's why was ignored in these changes. |
@Igloczek but still this commit was included in 2.2.6 version and the documentation with old calls are still there. And less:documentation is also called in Gruntfile.js. Nevertheless, with this I wanted to say that errors appear while doing grunt in the latest magento2 public version (2.2.6). |
CC @DrewML you might want to know about this problems. For me it should be considered as legacy and removed. If that's not possible, probably need some serious updates and some test coverage on CI, to be sure it at least cam be built. |
Original Pull Request
#11371
Backstory
It's not a secret that I don't like LESS, but because of SASS Blank project, I often have to deep dive into Magento UI LESS library code.
Unfortunately, 9 of 10 times I got a punch of weirdness of language "features" mixed with the inconsistency of the implementation right in the face.
That's why I decided to do something with it and clean up most annoying places.
It may be considered as heavily opinionated changes, but all of this code is 100% safe and didn't change the output CSS, the goal is to make working on this code less painful, especially for porting into languages that care more about scope and execution order, but it also should help people working directly on LESS, because all of the changes can be considered as a good practice in any programing language.
Technical reason of changes
In LESS variables have kinda weird scope rules, which I'm considering as a leaking scope and the source of confusion i.e. functions (mixins) invoked inside function declaration inherits all variables of the parent function.
An example in a JS-like code to show weirdness of the LESS scoping:
It's not a common practice in other languages used in FE development and it not clear for developers, so will be nice to avoid it.
The goal is to pass all necessary values to mixin only through parameters or using global variables as default values of parameters.
Same example, but with this new rules applied:
Description of changes
I removed all fallbacks to variables not existing in the global scope, defined all variables used inside mixins as parameters and added all missing parameters to the places where mixins are invoked.
Also mixin that was used just once, was moved and simplified, to reduce usage of weird LESS scoping, where variables defined in mixin are accessible in the place where mixin is invoked.