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
gatsby-plugin-sass: importing scss file in one page imports stying globally for all pages during development #28046
Comments
Thank you for opening this! This is expected behavior as per #11072 - we don't code-split CSS as it will result in unforeseen implications. If you're okay with those you can (like mentioned in #21728) override the webpack config, e.g. this plugin does it: https://github.com/staffe/gatsby-plugin-split-css We're marking this issue as answered and closing it for now but please feel free to comment here if you would like to continue this discussion. We also recommend heading over to our communities if you have questions that are not bug reports or feature requests. We hope we managed to help and thank you for using Gatsby! |
But this leads to another unforseen implication: This is a problem that many developers will face when they realize that there production site styling is different from their site during development. see this comment we need some guarantee that our website during development will look the same as it would on production. But currently as it stands, Gatsby might falsely apply css/scss styling to pages during development and give developers the illusion that css styling has been applied to a page in production, when it has not. this is something that gatsby users need to be aware of. this is a dangerous side-effect and bad developer experience because you get css styling on a page in dev mode when you haven't even imported css/scss file to that page. |
BTW, gatsby-plugin-split-css does not resolve the issue of css styling being applied to pages without explicitly importing css/scss file during development. I've attached an example gatsby project using gatsby-plugin-split-css: gatsby-site.zip. |
Hi and thanks for opening this issue. Have you figured proper solution since then? Thanks |
I'm not sure about a proper solution, but I've moved a lot of my styling from global scss into styled components using @emotion. I just accept that there is a global scss file and there is no way to split css. |
Actually, I still have some "global" (imported by Personally I don't want (nor expect) my styles to be inlined but I don't think that we have a choice. |
Description
During development (
gatsby develop
) css styling should only be applied to pages where I explicitly import.scss
file. However, importing.scss
file to a single page also applies css styling globally to all other pages that do not importscss
file.Steps to reproduce
gatsby new gatsby-site https://github.com/gatsbyjs/gatsby-starter-hello-world
npm i gatsby-plugin-sass sass
configure
gatsby-config.js
.scss
file(s) undersrc/scss
folder.scss
file in one (foo.js)index.js
foo.js
gatsby develop
Expected result
What should happen?
css styling should only be applied to the page importing
.scss
(foo.js
).css styling should not be applied to the page without the
.scss
import (index.js
)What happened.
css styling was applied to pages without
.scss
import (index.js
)Environment
System:
OS: Windows 10 10.0.18363
CPU: (8) x64 Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
Binaries:
Node: 14.15.0 - C:\Program Files\nodejs\node.EXE
npm: 6.14.8 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: 86.0.4240.198
Edge: Spartan (44.18362.449.0)
npmPackages:
gatsby: ^2.25.3 => 2.25.3
gatsby-plugin-sass: ^2.5.1 => 2.5.1
npmGlobalPackages:
gatsby-cli: 2.12.117
gatsby-site.zip
The text was updated successfully, but these errors were encountered: