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

Selector only present @nested is dropped from CSS module in build #4496

Closed
tremby opened this issue Mar 12, 2018 · 4 comments
Closed

Selector only present @nested is dropped from CSS module in build #4496

tremby opened this issue Mar 12, 2018 · 4 comments

Comments

@tremby
Copy link
Contributor

tremby commented Mar 12, 2018

Description

I'm making use of the CSS nesting at-rule, which I believe is provided to us by cssnext.

I noticed some things which were working in development were broken when I built my site, and I traced it to the at-rule.

When in a CSS module, classes which only appear under a @nest are dropped during the build.

Steps to reproduce

Check out this repository, which is the basic starter with a few elements and a CSS module added.

https://github.com/tremby/gatsby-nest-bug

In particular, the test code is:

    <p className={styles.green}>green</p>
    <p className={styles.yellowbg}>yellowbg</p>
    <p className={styles.red}>red</p>
    <p className={styles.orangebg}>orangebg</p>
    <div className={styles.yellowbg}>
      <p className={styles.green}>green in yellowbg</p>
    </div>
    <div className={styles.orangebg}>
      <p className={styles.red}>red in orangebg</p>
    </div>

With CSS

.green {
  color: green;

  @nest .yellowbg & {
    background-color: yellow;
  }
}

.red {
  color: red;

  @nest .orangebg & {
    background-color: orange;
  }
}

.orangebg {}

Run it in development mode and see the output. Then build it and view again.

Expected result

screenshot-expected

both in development and when built.

Actual result

The correct result when in development, and the following when built.

screenshot-actual

The line "green in yellowbg" should be on a yellow background.

The line "red in orangebg" is working, but only because I added a stub .orangebg {} rule.

Environment

File contents (if changed):

gatsby-config.js: not changed
package.json: not changed
gatsby-node.js: not changed
gatsby-browser.js: not changed
gatsby-ssr.js: not changed

@m-allanson
Copy link
Contributor

m-allanson commented Mar 16, 2018

Hey @tremby, this is strange. I'm not sure what's happening here but it sounds like a bug.

It'd be great to see a PR solving this. Check out the contributing docs if you'd like to take a crack at fixing it.

@KyleAMathews
Copy link
Contributor

Due to the high volume of issues, we're closing out older ones without recent activity. Please open a new issue if you need help!

@tremby
Copy link
Contributor Author

tremby commented Sep 9, 2018

Hm, I'm actually not sure whether it's still relevant. @KyleAMathews, am I right that Gatsby 2 removes cssnext?

@KyleAMathews
Copy link
Contributor

Yeah

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