Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.

3.0.0 CSS Variable hyphen compiling change #403

Closed
drwpow opened this issue Jul 7, 2017 · 10 comments
Closed

3.0.0 CSS Variable hyphen compiling change #403

drwpow opened this issue Jul 7, 2017 · 10 comments

Comments

@drwpow
Copy link

drwpow commented Jul 7, 2017

Take 2 CSS variables:

:root {
  --space: 32px;
  --space-075: 24px;
}

In both 2.9.x and 3.0.0, the variables compile correctly when used by themselves. However, something interesting happens when you try and invert those values:

2.9.x

margin-left: -var(--space); // -32px
margin-bottom: -var(--space-075); // -24px

3.0.0

margin-left: -var(--space); // -32px
margin-bottom: -var(--space-075); // 24px !!!

I rolled back my version to double-test, and confirmed it’s compiling differently with 3.0.0. Am I missing something? Are hyphens not part of the variable spec? Is it bad practice to prepend/append CSS variables?

@drwpow drwpow changed the title 3.0.0 CSS Variable hyphen compiling error 3.0.0 CSS Variable hyphen compiling change Jul 7, 2017
@MoOx
Copy link
Owner

MoOx commented Jul 7, 2017

Please provide correct examples.
I guess you are providing this

:root {
  --space: 32px;
  --space-075: 24px;
}

body {
  margin-left: -var(--space);
  margin-bottom: -var(--space-075);
}

and expect this

body {
  margin-left: -32px;
  margin-bottom: -24px;
}

If that's the case (cause I don't understand the -075 purpose otherwise), it's working this way on the playground http://cssnext.io/playground/

@MoOx MoOx closed this as completed Jul 7, 2017
@drwpow
Copy link
Author

drwpow commented Jul 7, 2017

@MoOx I did. Good catch. The playground is using 3.0.0?

@MoOx
Copy link
Owner

MoOx commented Jul 7, 2017

Playground is using the version you can see below the logo

screen shot 2017-07-07 at 17 29 30

So yes :)

@drwpow
Copy link
Author

drwpow commented Jul 7, 2017

Cool. I’m consistently getting the compiled results I stated, and the version bump affects it. But I am running it through vue-loader. Again, weirdly, changing the cssnext version in package.json is the deciding factor between it compiling correctly or not, but it might be some obscure interaction with vue-loader that’s the issue. I’ll investigate more and open another issue if it’s applicable to this repo.

Thanks for your time! 🍻

@tranan89
Copy link

@DangoDev Did you find what it was? We are having the same issue after upgrading cssnext and webpack to 3. We don't use vue

@Pelsin
Copy link

Pelsin commented Aug 10, 2017

@MoOx @DangoDev I am having the same issue, although the problem arise when using var in combination with calc. Manage to reproduce in playground.

:root {
 --marginLeft: calc(12 / 10)px;
 --marginRight: 10px;
}

div {
  margin-left: -var(--marginLeft);
  margin-right: -var(--marginRight);
}

Result:

div {
  margin-left: 1.2px;
  margin-right: -10px;
}

I guess this falls on postcss-calc plugin.

@MoOx
Copy link
Owner

MoOx commented Aug 10, 2017

calc(12 / 10)px is not valid in the first place

@Pelsin
Copy link

Pelsin commented Aug 10, 2017

Alright! That is good to know, will change in my implementation 👍

Although i'm not sure how that affects the hyphen.
As this produces same result in playground:

:root {
 --marginLeft: calc(2px * 2);
}

div {
  margin-left: -var(--marginLeft);
}

Even unit-less produces without the hyphen.

@MoOx
Copy link
Owner

MoOx commented Aug 10, 2017

Indeed that's a postcss-calc bug. I opened this MoOx/reduce-css-calc#30

@drwpow
Copy link
Author

drwpow commented Aug 10, 2017

Did you find what it was?

@tranan89 No; I’ve just been dancing around the issue introduced in 3.0.0. It’s still a problem for me. But for some reason I had trouble recreating the bug in the playground, so I was thinking it was something bizarre happening in the stack somewhere.

I’m glad others were able to reproduce it! I just haven’t had the time to isolate the bug and follow up.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants