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

"px" is removed from style attribute in template literal strings (lit-html) #1251

Open
vmizgiris-equinix opened this issue May 2, 2023 · 4 comments

Comments

@vmizgiris-equinix
Copy link

vmizgiris-equinix commented May 2, 2023

px is being removed from a style definition in template literal strings (lit-html).

Environment

  • clean-css version: 5.3.2
  • node.js version: 16.18.1
  • operating system: macOS Ventura 13.3.1

Configuration options

var CleanCSS = require('clean-css');
new CleanCSS();

Input CSS

const getSize() {
  return 20;
}
style="--size: ${getSize()}px"

Actual output CSS

style="--size:20"

Expected output CSS

style="--size:20px"
@jakubpawlowicz
Copy link
Collaborator

Hi @vmizgiris-equinix - what kind of CSS is it?

@vmizgiris-equinix
Copy link
Author

vmizgiris-equinix commented May 4, 2023

@jakubpawlowicz, sorry - completely jumped my mind to mention this. This is lit-html template code, which in turn is JavaScript template literal strings. For example:

import { html } from 'lit-html';

render() {
  return html`<my-component style="--size: ${getSize()}px"></my-component>`;
}

My code uses the minify-html-literals plugin under the hook which in turn uses clean-css.

I've gotten around this issue by doing style=${style} and set up my style in a variable, but ideally this should work.

(Edited the issue title and description for clarity)

@vmizgiris-equinix vmizgiris-equinix changed the title "px" is removed if style attribute uses an interpolated value "px" is removed in style attribute in template literal strings (lit-html) May 4, 2023
@vmizgiris-equinix vmizgiris-equinix changed the title "px" is removed in style attribute in template literal strings (lit-html) "px" is removed from style attribute in template literal strings (lit-html) May 4, 2023
@vmizg
Copy link

vmizg commented Jun 3, 2023

Looks like there were a few other similar issues raised in the past, both using a similar syntax:

asyncLiz/minify-html-literals#31

asyncLiz/minify-html-literals#46

@vmizg
Copy link

vmizg commented Sep 4, 2023

@jakubpawlowicz, do you have any updates on this?

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

No branches or pull requests

3 participants