magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.39k stars 9.29k forks source link

@font-size-unit-convert affects unitless values #25592

Open Leland opened 4 years ago

Leland commented 4 years ago

Preconditions (*)

Magento v2.3.1 & 2.3-develop

Steps to reproduce (*)

Compile this LESS under either blank or Luma:

.foo-bar {
  .lib-line-height(1);
}

Expected result (*)

.foo-bar {
   line-height: 1;
}

Actual result (*)

.foo-bar {
   line-height: 0.1rem;
}

This is the underlying mixin powering many, many lib- mixins across the site, for instance lib-button(), and thus this issue pertains to e.g @button__line-height: 1;.

As you follow the issue, you realize this is systemic in the way the plumbing for these mixins operates:

https://github.com/magento/magento2/blob/54742d5150fa97d08defd89226ddf5cc87aefa85/lib/web/css/source/lib/_utilities.less#L14-L23

@font-size-unit is defaulted to rem, and thus the mixin will always convert to this, even if it's not needed. I'll note that this behavior is disabled when @font-size-unit-convert: false, though this is not the default under either blank or Luma.

A simple fix would be to add a guard clause utilizing LESS' built-in get-unit() function, which returns falsey if the value passed is unitless.

m2-assistant[bot] commented 4 years ago

Hi @Leland. Thank you for your report. To help us process this issue please make sure that you provided the following information:

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

@Leland do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?


Leland commented 4 years ago

@magento give me 2.3-develop instance

magento-engcom-team commented 4 years ago

Hi @Leland. Thank you for your request. I'm working on Magento 2.3-develop instance for you

magento-engcom-team commented 4 years ago

Hi @Leland, here is your Magento instance. Admin access: https://i-25592-2-3-develop.instances.magento-community.engineering/admin Login: admin Password: 123123q Instance will be terminated in up to 3 hours.

m2-assistant[bot] commented 4 years ago

Hi @engcom-Charlie. 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:

magento-engcom-team commented 4 years ago

:white_check_mark: Confirmed by @engcom-Charlie Thank you for verifying the issue. Based on the provided information internal tickets MC-23200 were created

Issue Available: @engcom-Charlie, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

krzksz commented 4 years ago

I've just checked the issue and according to the docs of .lib-line-height the conversion to rem is there by design, which is even outlined in the example provided.

Leland commented 4 years ago

@krzksz respectfully, I'm not sure you understand the issue. This issue is not with lib-line-height() specifically.

See the title: "@font-size-unit-convert affects unitless values." lib-line-height() happens to be a function which has errors because of the issues in the unit conversion plumbing underneath: unitless values are a standard part of CSS, and Magento's internal mixins do not support them.

@button__line-height: 1 will cause a theme based on default blank or Luma to output 0.1rem, which you hopefully can agree is an issue - documentation to the opposite notwithstanding.

Regardless, those docs are not actually correct - not only is there no fallback to px, calculates line-height in **rem** is not accurate either. lib-line-height() converts to whatever @font-size-unit is set to - that could be rem, or em, or any other CSS unit supported by LESS.

krzksz commented 4 years ago

Hey @Leland, thanks for the clarification, I totally understand that unitless values are completely valid for line-height according to CSS specification and I would really like Magento to support them.

That said, I've already tried a lot of different variations and changes to .lib-line-height which resulted in:

//  Rem line height
.lib-line-height(@heightValue) when (isnumber(@heightValue)) and not (ispercentage(@heightValue)) and not (get-unit(@heightValue) = ~'') {
    .lib-font-size-value(@heightValue);
    .lib-css(line-height, @fontValue);
}

.lib-line-height(@heightValue) when (ispercentage(@heightValue)), (isnumber(@heightValue)) and (get-unit(@heightValue) = ~'') {
    .lib-css(line-height, @heightValue);
}

there are two problems with this (and all of the other that I tried) solution:

  1. I have no idea what will be the side effects of such change, because...
  2. ...compiler for less seems to not respect logical order of conditions and because of the fact that sometimes false is passed as an argument, compiling fails with:
    error evaluating function `get-unit` Notice: Undefined property: Less_Tree_Keyword::$unit
krzksz commented 4 years ago

Since I'm quite out of ideas how to solve it from the code perspective (maybe some other way will enlighten me), I'm planning so file a separate issue that outlines this problem with a parser so we can proceed our work here.

magento-engcom-team commented 4 years ago

:white_check_mark: Confirmed by @engcom-Charlie Thank you for verifying the issue. Based on the provided information internal tickets MC-29004 were created

Issue Available: @engcom-Charlie, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

mrtuvn commented 4 years ago

@Leland if it's only affected in line height case why not use native property instead mixins. You can controll value you want Some case you don't want convert to rem you can set @font-size-unit-convert: false; in top of customises less

Just curiousity how this @font-size-unit-convert can affect to other property if use unitless

Leland commented 4 years ago

why not use native property instead mixins

Setting global button line-heights to 1 is a very common use case here, as outlined above. On a default instance of Luma, that would produce an output of 0.1rem. That's clearly not intended or correct output one way or another, and we can't expect developers to look at that 0.1rem and think "oh, I should just be using properties, not the mixin!"

We should definitely support unitless values on this IMO.

At absolute worst, we could just have functions die on unitless input. I don't support that approach, but it would at least be an explicit one.

mrtuvn commented 4 years ago

ok i see plenty usage line-height around button here. Undoubtedly we need refactor to work with unitless

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Thank you for your contributions.

Leland commented 3 years ago

This is still important to me.