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

Faulty nesting detection with at-rules #214

Closed
cheeaun opened this issue May 29, 2017 · 10 comments
Closed

Faulty nesting detection with at-rules #214

cheeaun opened this issue May 29, 2017 · 10 comments
Labels

Comments

@cheeaun
Copy link

cheeaun commented May 29, 2017

I upgraded to the latest version of styled-jsx at 1.0.1 and been getting this error:

[Error: Nesting detected at 0:80. Unfortunately nesting is not supported by styled-jsx.]

Did a little research, ran tests on both styled-jsx and stylis, found that:

test("doesn't throw when using media queries", t => {
  t.notThrows(() =>
    transform('', '@media (min-width: 480px) { div { color: red } }')
  )
})

This is the current test and it passes

test("doesn't throw when using media queries", t => {
  t.notThrows(() =>
    transform('', 'span {} @media (min-width: 480px) { div { color: red } }')
  )
})

Added a faux span and this passes too ✅

BUT...

test("doesn't throw when using media queries", t => {
  t.notThrows(() =>
    transform('', `span {}
      @media (min-width: 480px) { div { color: red } }`)
  )
})

Add a newline and this fails

test("doesn't throw when using media queries", t => {
  t.notThrows(() =>
    transform('', `@media (min-width: 480px) { div { color: red } }
      span {}`)
  )
})

If the lines are flipped around, this passes ✅ 😅

I suspect this is relevant to thedisableNestingPlugin method in style-transform.js and the cascade: false option passed into stylis. This applies to @keyframes too.

@giuseppeg
Copy link
Collaborator

giuseppeg commented May 29, 2017

@cheeaun thanks for the amazing and detailed bug report! You are correct the bug should be in disableNestingPlugin or Stylis itself.

Would you have time to further debug disableNestingPlugin? If not I will take a look at it tonight or tomorrow. You can find the relevant docs here https://github.com/thysultan/stylis.js#plugins

@giuseppeg giuseppeg added the bug label May 29, 2017
@cheeaun
Copy link
Author

cheeaun commented May 29, 2017

@giuseppeg I've also tried to replicate the bug on stylis, with the exact same CSS code and even the same config {cascade: false, compress: true}. It passes ✅ there.

I suspect that when cascade: false, the context becomes different (2) or something (I console.log-ed everything in the disableNestingPlugin method). So I'm not sure if it needs special handling in the method or context is wrongly handled here 🤔

@thysultan
Copy link
Contributor

thysultan commented May 29, 2017

This happens because div { color: red } is a parent of @media (min-width: 480px) so you may need to take that into account by allowing @at-rules as valid nesting parents, e.x making an exception when the first character is @

@giuseppeg
Copy link
Collaborator

@thysultan yep that indeed fixes @cheeaun's issue. Mind taking a look at the PR #216 ?

However there seem to be a bug in Stylis and media queries are prefixed

span {}
      @media (min-width: 480px) { div { color: red } }

/* @media[prefix](min-width[prefix]:480px[prefix]) div[prefix]{color:red} */
:hover {}
      @media (min-width: 480px) { div { color: red } }

/* @media[prefix](min-width[prefix]:480px[prefix]) div[prefix]{color:red} */
:hover { color: green }
  @media (min-width: 480px) { div { color: red } }

/* [prefix]:hover{color:green}@media[prefix](min-width[prefix]:480px[prefix]) div[prefix]{color:red} */

@thysultan
Copy link
Contributor

@giuseppeg Interesting, i see what could be the issue there.

giuseppeg added a commit that referenced this issue May 30, 2017
@giuseppeg
Copy link
Collaborator

published 1.0.2 to npm @cheeaun @thysultan thanks for your help! <3

@zhangfaliang
Copy link

zhangfaliang commented May 25, 2018

Will also appear
error info ‘Unfortunately nesting is not supported by styled-jsx.
at Function.disableNestingPlugin’
code

 .changeSp{
              position:absolute;
              right:30px;
              top:30px;
              width:0;  
              height:0;  
              margin:0 auto;  
              border:10px solid transparent;  
              animation: animations 5s cubic-bezier(0, 0, 0.48, 0.45) forwards;

            }
          
            @keyframes animations{
                0%{opacity:0;}
                100%{opacity:1;}
            }

@giuseppeg
Copy link
Collaborator

@thysultan could it be a parsing issue? Or do you think that is our plugin's fault?

@thysultan
Copy link
Contributor

thysultan commented May 25, 2018

@giuseppeg The latter, specifically related to #313 (review).

@giuseppeg
Copy link
Collaborator

@thysultan awesome thank you!

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

No branches or pull requests

4 participants