-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
develop vs build styles mismatch due to sass imports #19563
Comments
gatsby build
vs gatsby develop
styles mismatch due to sass imports
It's important to note that this also happens with Office UI Fabric components, which is huge. I'm writing a webapp with Gatsby and Office UI Fabric React, which is scss based, and this is exactly what's happening! I hope someone will fix this, 'cause disabling rehydration is not a solution at all... |
Does this seem like something related to gatsby-plugin-sass? There doesn't seem like there's any prod vs. develop in the plugin unless I'm missing something https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-plugin-sass/src/gatsby-node.js |
Good thinking. |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. Thanks for being a part of the Gatsby community! 💪💜 |
Don't go spooky quiet... |
Hey, I have looked at your issue here and what you're talking about looks like ICSS. ICSS is part of the css-modules spec. css-modules is only enabled on files with the I'm marking this issue as answered and closing it for now but please feel free to reopen this and comment if you would like to continue this discussion. We hope we managed to help and thank you for using Gatsby! 💜 |
Hi @wardpeet Please reopen this; I can see how this looks like ICSS since the syntax is exactly the same, but sass exports are actually also a sass feature that should work independently of ICSS. They are specified with the
Note that in this specific case, using the .module syntax indeed fixes it, but if layout.scss contained any CSS classes or ids, all of those would be broken by using the CSS module syntax. As I said in a previous comment, this bug seems to be caused by the sassRule in gatsby-plugin-sass, which does not use the importLoaders when server side rendering. I'll send a PR with a simple fix. |
Seems the first PR was on my own repo ;) |
This doesn't seem to be the case. Pure Sass just passes It is |
@vladar However, using the module syntax will also break all classes and ids, which would need to be prefixed with the import name. So I guess this also means there is no 'simple fix' for this bug? |
The bug is that we shouldn't allow this on develop or production rehydration as this is not a css/sass/less feature but a css-modules one. An option you could do is create a json or js file which holds your variables and use the This should roughly look like this inside your gatsby-config.js file.
|
OK, that makes sense. In this case, it would definitely make more sense if none of the imports worked, neither in dev nor prod. But I believe this would also complicate things for a lot of people, so it might be wise to get an idea first of how many people depend on this behavior. Thanks for the suggestion. |
Description
Variables imported from a sass stylesheet are undefined on
gatsby build
, but work fine ongatsby develop
. This results in obscure bugs that only manifest themselves on first page load in production.I believe this might be the cause of some of these 'mysterious' issues where
gatsby build
styles differ fromgatsby develop
, since this probably also happens to each theme or plugin that uses preprocessor imports.Steps to reproduce
Minimal reproduction based on
gatsby-starter-default
:https://github.com/DavidDeprost/gatsby-build--sass-bug
Run
gatsby develop
, and you'll see the background is violet.Run
gatsby build && gatsby serve
, and you'll see it remains white, but turns violet when going to page 2 and back.Expected result
Sass imported variables should not be undefined on build, so the background is violet from the start, both in development and production.
Actual result
Background remains white on first page load in production.
Environment
The text was updated successfully, but these errors were encountered: