-
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
[v2] gatsby - Duplicate styles when serving site #7517
Comments
I can reproduce. The problem is not with The problem is related with the Since in By removing unique |
Ah yeah so it is a bug. Hope this can be fixed! Maybe just check the hashes to see if they're the same file contents? |
Happening to me as well on V2, when preloading by hovering a link with different layout I'm getting duplicated code that overwrites the one on my current page. Happening to me with Update 1 (no success yet): I have also tried putting all the CSS in one main file and importing it in the |
Ok, so I have found a temporal approach that works for my case, it's not ideal but I'll explain it here anyway in case it helps someone else with the same problem and a similar project structure. Context/Problem:
In my case, as I said, the blog does not contain too much CSS so I thought that having a single file main.scss and putting it in the layout component would stop the duplicated CSS code but... it didn't. Solution: I just added this line to my gatsby-browser.js and removed it from the layout component:
Note: I'll still try to dig in a little more in how gatsby constructs the CSS to see if I can be able to use CSS modules with SASS without having the code duplication between the sections, it wont be a priority in my daily tasks, but in the meantime I hope that this helps someone. |
Thanks @enmanuelduran - Ill check this out on my end |
This cause two issues for me, one which could be fixed with better CSS architecture on my part. Firstly I also included my base CSS in a layout component, and in that, I loaded my fonts. When I hovered over a link for the first time I would see all the fonts be reloaded and the entire site flash. I solved this by simply moving those includes into My second problem is when the CSS is reloaded, some components that include universal selectors get reloaded a win specificity over components in the page already. This causes the layout to break. I'm new to CSS Modules, so I think I could design my architecture better and it should solve the problem. For now I will just make sure the specificity always wins regardless of source order as a quick fix. This fixes my layout problems but there is lots of wasted bytes tied to this. I'm not 100% sure if the problem stems from this, but when hovering over some links, some of the CSS that is loaded is from a different file unique to that component, but the contents are identical to other page components. There's no deduping happening. It might also be worth noting that I'm not using |
I have a lot of CSS files, with the assumption that the module bundling would put them in the correct order. I don't want to have to worry about specificity, that's the point of CSS Modules. I realized that simply using |
The CSS in production doesn't behave the same as in development. The main problem is that hovering over links appends CSS from that route, but that CSS is already included and it messes up the specificity. The only workaround that I know of is avoiding Gatsby's Link component until that issue gets resolved. Too bad, prefetching was pretty cool. gatsbyjs/gatsby#7517
@silvenon this is what I ended up doing for now, does using have any performance benefits? |
|
Hi! I also ran into this issue - or a very similar one - in production. While swapping So, assume ExampleComp has some modular class - we'll call it
I've had to fiddle quite a bit with different webpack configs to get everything lined up, but I can't seem to shake this bug. Has anyone seen anything similar? |
@alexjhannan I'm seeing a very similar issue on my website. It doesn't break the functionality, but it certainly puts a hiccup in the user experience. I've been fiddling with it for most of today and can't seem to find anything. Let me know if you're able to come up with a solution, and we can go from there. |
I resolved it using #7517 (comment) |
But it's a workaround for an actual bug, I don't think this should be closed. If that's a recommendation from Gatsby team, I think it's best if the starter and docs are also updated to use I guess code-splitting and SSR are really tricky for CSS files. 😕 Probably because importing a CSS file has an immediate side-effect of injecting it into the document, so hovering over the link actually injects the stylesheet. |
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. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open! Thanks for being a part of the Gatsby community! 💪💜 |
This has probably been solved by #11800, I think it stems from the same issue. |
@silvenon I've just updated my site locally and there seems to be no duplication errors. Can anyone else confirm? |
Closing this as #11800 solved the issue for me. |
Now Gatsby no longer has issues with duplicating styles when preloading. gatsbyjs/gatsby#7517
Description
Seeing duplicate style declarations when serving the site.
Not sure if this is a webpack issue or not?
Steps to reproduce
gatsby serve
Environment
System:
OS: macOS High Sierra 10.13.5
CPU: x64 Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz
Shell: 5.3 - /bin/zsh
Binaries:
Node: 9.2.0 - ~/.nvm/versions/node/v9.2.0/bin/node
Yarn: 1.6.0 - ~/.nvm/versions/node/v9.2.0/bin/yarn
npm: 5.8.0 - ~/.nvm/versions/node/v9.2.0/bin/npm
Browsers:
Chrome: 68.0.3440.106
Firefox: 60.0.2
Safari: 11.1.1
npmPackages:
gatsby: next => 2.0.0-rc.0
gatsby-image: next => 2.0.0-rc.0
gatsby-plugin-catch-links: next => 2.0.2-rc.0
gatsby-plugin-manifest: next => 2.0.2-rc.0
gatsby-plugin-netlify: next => 2.0.0-rc.0
gatsby-plugin-nprogress: next => 2.0.0-rc.0
gatsby-plugin-offline: next => 2.0.0-rc.0
gatsby-plugin-react-helmet: next => 3.0.0-rc.0
gatsby-plugin-sass: next => 2.0.0-rc.0
gatsby-plugin-sharp: next => 2.0.0-rc.0
gatsby-source-contentful: next => 2.0.1-rc.0
gatsby-transformer-remark: next => 2.1.1-rc.0
gatsby-transformer-sharp: next => 2.1.1-rc.0
npmGlobalPackages:
gatsby-cli: 1.1.58
File contents (if changed)
gatsby-config.js
:package.json
:gatsby-node.js
:gatsby-browser.js
:gatsby-ssr.js
: N/AThe text was updated successfully, but these errors were encountered: