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

Resolve Opacity Bug #881

Merged
merged 2 commits into from
Feb 21, 2020
Merged

Resolve Opacity Bug #881

merged 2 commits into from
Feb 21, 2020

Conversation

genemecija
Copy link
Contributor

Resolving bug in which opacity values defined as percentages are being converted to 1%.

@codecov-io
Copy link

codecov-io commented Feb 21, 2020

Codecov Report

Merging #881 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #881   +/-   ##
=======================================
  Coverage   97.27%   97.27%           
=======================================
  Files         118      118           
  Lines        3452     3452           
  Branches     1035     1036    +1     
=======================================
  Hits         3358     3358           
  Misses         86       86           
  Partials        8        8
Impacted Files Coverage Δ
packages/postcss-convert-values/src/index.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 613d562...8a0a310. Read the comment docs.

Copy link
Member

@anikethsaha anikethsaha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Catch 👍

Can you add few tests in postcss-convert-values for future use.

'should preserve opacities defined as percentages',
passthroughCSS('h1{opacity:100%}')
);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some more.

may be like these
⬇️

test(
  'should convert the opacity to 1px',
  processCSS('h1{opacity : 80px}', 'h1{opacity: 1px}')
);
test(
  'should convert the opacity from 80% -> 80%',
  processCSS('h1{opacity :80%}', 'h1{opacity :80%}')
);

Also check this one
⬇️

test(
  'should convert the opacity without any unit',
  passthroughCSS('h1{opacity :80}')    // expected is 80
);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding your tests:

test(
  'should convert the opacity to 1px',
  processCSS('h1{opacity : 80px}', 'h1{opacity: 1px}')
);

'px' is not a valid unit, and I opted not to check for invalid units as that's not the tool's purpose (minification vs linting)


test(
  'should convert the opacity from 80% -> 80%',
  processCSS('h1{opacity :80%}', 'h1{opacity :80%}')
);

If I'm not mistaken, processCSS('h1{opacity :80%}', 'h1{opacity :80%}') would be the same test as passthroughCSS('h1{opacity:80%}') or the test I created, passthroughCSS('h1{opacity:100%}'). Please correct me if I'm wrong about that.


test(
  'should convert the opacity without any unit',
  passthroughCSS('h1{opacity :80}')    // expected is 80
);

Any number above '1.0' is invalid and would be converted to '1'. There's a check for this at line 281:

test(
  'should clamp opacity to 1 maximum',
  processCSS(
    'h1{opacity:150;opacity:15;opacity:1.5}',
    'h1{opacity:1;opacity:1;opacity:1}'
  )
);

The only other tests I can think that aren't already tested for are for validating unit type, but that would be a linter's job.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding your tests:

test(
 'should convert the opacity to 1px',
 processCSS('h1{opacity : 80px}', 'h1{opacity: 1px}')
);

'px' is not a valid unit, and I opted not to check for invalid units as that's not the tool's purpose (minification vs linting)

Invalid CSS should lean to either no minification or invalid minification. This is an example of invalid minification.
You can keep it or omit it. either looks good.
but I would check the behavior by keeping it for future use

If I'm not mistaken, processCSS('h1{opacity :80%}', 'h1{opacity :80%}') would be the same test as passthroughCSS('h1{opacity:80%}') or the test I created, passthroughCSS('h1{opacity:100%}'). Please correct me if I'm wrong about that.

Yea, but I prefer using processCSS as its more visible. again your choice to use either of them. but they both are fine 👍

Any number above '1.0' is invalid and would be converted to '1'. There's a check for this at line 281:

if its done, leave it then 👍

The only other tests I can think that aren't already tested for are for validating unit type, but that would be a linter's job.

Feel free to choose whether to test it or not. @evilebottnawi what you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to use passthroughCSS when values was not changed, I think in future we refactor tests on snapshots, because it is more easy to read

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is an original problem, I lose context, can you provide example? Or a link on issue?

@anikethsaha
Copy link
Member

What is an original problem, I lose context, can you provide example? Or a link on issue?

This is the current behavior

opacity : 40% -> opacity : 1%

It is wrong minification

@alexander-akait
Copy link
Member

@genemecija opacity : 40% is invalid css syntax, why you need that line?

@anikethsaha
Copy link
Member

@genemecija opacity : 40% is invalid css syntax, why you need that line?

@evilebottnawi I think this is an correct syntax. I tried on developer tools. its working

@alexander-akait
Copy link
Member

hm, yes, you are right https://developer.mozilla.org/en-US/docs/Web/CSS/opacity, never use % 😄

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@herecydev
Copy link

@evilebottnawi was there a release for this patch?

@alexander-akait
Copy link
Member

@herecydev yes, in future, still a lot of work

@SylvainGarrigues
Copy link

Any possibility for a hot bug fix release instead of waiting for a new formal release with other features? This is breaking UI for sites in production which rely on cssnano.

X% (unminified) -> 1% (minified) means elements become invisible in production builds and not in development builds. Can drive people crazy.

@anikethsaha
Copy link
Member

it will be done soon.
in the meantime use postcss-ignore-plugin or I would suggest disabling this plugin

@svendlarsen
Copy link

@anikethsaha @evilebottnawi Please reconsider making a separate patch release for this bugfix! Three months is a long time between merge and release for a fix of this nature.

@anikethsaha
Copy link
Member

it will be released soon, #881 (comment)

@klesun
Copy link

klesun commented Aug 13, 2020

um, bump? Guys, your lib is used by a decent amount of people, would you consider making the hotfix release asap, please? Is 4.0.0-nightly.2020.8.10 behind 4.1.10?

@anikethsaha
Copy link
Member

Please use cssnano@nightly in the meantime

@anikethsaha
Copy link
Member

nightly is up-to-date with the master

nt-gt pushed a commit to dcsaorg/P6-Application that referenced this pull request Oct 1, 2021
See cssnano/cssnano#881

Signed-off-by: Niels Thykier <nt@asseco.dk>
nt-gt pushed a commit to dcsaorg/P6-Application that referenced this pull request Oct 1, 2021
Work around cssnano/cssnano#881.

Signed-off-by: Niels Thykier <nt@asseco.dk>
nt-gt pushed a commit to dcsaorg/P6-Application that referenced this pull request Oct 1, 2021
Work around cssnano/cssnano#881.

Signed-off-by: Niels Thykier <nt@asseco.dk>
alex-ketch added a commit to stencila/thema that referenced this pull request Oct 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants