styled-jsx icon indicating copy to clipboard operation
styled-jsx copied to clipboard

Throws `Unfortunately nesting is not supported by styled-jsx` when using CSS comments before @media queries

Open antonj opened this issue 8 years ago • 11 comments

Added failing test here https://github.com/antonj/styled-jsx/commit/c357234a331dc971f88ca667a8291822a18c703b

div { color: red; }
/* CSS Comment */
@media screen and (min-width: 480px) {
  div { color: red; }
}

Throws Unfortunately nesting is not supported by styled-jsx if /* CSS Comment */ is removed the tests pass.

antonj avatar Dec 13 '17 19:12 antonj

Tried to include a local styled-jsx plugin but even (css, options) => css which does not transform the css gives the nesting error

Pro542 avatar Dec 14 '17 03:12 Pro542

Has anyone figured out a fix for this yet? I just did a fresh npm i and now I can't get back to a working state at all.

jabacchetta avatar Dec 20 '17 07:12 jabacchetta

I'm using styled-jsx with stylus plugin and there are no problems with comments in styles. Maybe this could be a workaround until it gets fixed.

P.S. If you don't want to use stylus or other preprocessors you can try to use postcss-discard-comments with postcss plugin just to discard comments ;)

a-ignatov-parc avatar Dec 20 '17 07:12 a-ignatov-parc

will look into this in the following days

giuseppeg avatar Dec 20 '17 08:12 giuseppeg

@giuseppeg Just FYI, I had a few minutes to play around with this today. I don't believe it has anything to do with comments.

I copy/pasted what @antonj had without the comments and it did work. But then I attempted to modify my own media query (which did not have any comments but was failing), and I had it down to exactly what he had, yet it still failed. Then I started copy pasting in bits from his code and messing with spacing and eventually got it to work.

So it seems as though spacing has something to do with it. I'll try to experiment more tonight if I have the time.

jabacchetta avatar Dec 20 '17 23:12 jabacchetta

styled-jsx @giuseppeg OK, for me, I simply had to remove the spacing that was on the line break immediately preceding the media query declaration. That fixed it, although no idea why yet. Hopefully that helps somewhat.

jabacchetta avatar Dec 20 '17 23:12 jabacchetta

Yes, it worked . Just remove extra spaces before media query.!!

pritambinbill avatar Dec 21 '17 12:12 pritambinbill

@antonj I tried to add that css to the tests but they still pass. Do you mind creating a pull request with your code? Do you use tabs for indentation?

@jabacchetta same with your code.

giuseppeg avatar Dec 21 '17 18:12 giuseppeg

@giuseppeg Seems like the CSS-comment has nothing to do with it, a line with either a space or a TAB in it will fail the tests. https://github.com/thysultan/stylis.js/issues/59 might be relevant?

antonj avatar Dec 22 '17 10:12 antonj

@jabacchetta, @cpugirl thanks, removing the newline before @media worked for me

farookisonfire avatar Jan 09 '18 21:01 farookisonfire

I found the bug, for some reason your editor inserts the NULL character \u0000

giuseppeg avatar Jan 27 '18 08:01 giuseppeg