-
Notifications
You must be signed in to change notification settings - Fork 8
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
Why do we need linaria with gatsbyjs? #94
Comments
I'm just a user, but here's my take: Because after Gatsbyjs loads the initial static html with the Also, if you use dynamic styling with those other libraries, you may run into performance costs due to how they manage styles. You can read this article for a deeper analysis That being said, it all depends on your app and how you feel about the (non)issues I pointed out. EDIT: Here's another link to read that may give you more insight for a decision |
I read your question over and over again, but I'm not sure what you're asking. The overhead that comes from styled-components and emotion applies to Gatsby sites, too, so the benefits of zero-runtime CSS-in-JS libraries are the same. I'll close this because it's not a bug report, but we can keep the discussion going. |
I thought gatsbys build process extract CSS to separate stylesheets. |
@kaushalyap gatsby creates static pages by server-side rendering your pages during the build stage. Therefore it can only do what packages enable for SSR.
Here's an explanation from the creator of the library styled-components/styled-components#1018 (comment) And here's another thread with authors from both libraries providing explanations |
~ comment @JM-Mendez So does the gatsbys build process split CSS bundle by route inorder to avoid unnecessary CSS loading? |
Found the answer
~ comment
Since gatsby do code splitting and use the mini-css-extract-plugin so the CSS should be also split. |
Just wanted to add that the StyledComponents/Emotion runtime won't be gone after SSR and some or all CSS has been inlined. They're normal and heavy JS modules which will stay in your Gatsby website as they need the runtime to do their work. I think in Gatsby all styles will be inlined in the head, not just critical 🤔 Wasn't sure that was understood before. Anyway... 😁 |
As already mentioned above, Linaria still has an advantage because it does not require an initial mount or computational cost. This is exactly what "Zero runtime" means. For Critical CSS Extraction, it is recommended to analyze the actual case. Most libraries describe it in the Server Side Rendering section, but Gatsby and Linaria both are static, so the approach should be quite different. This means that every possible stylesheet in the app must be determined at the build time. This is different from Emotion/SC. In Emotion, there is a runtime that manipulates CSSOM directly, hydrated stylesheets from the initial markup. Gatsby removes the server runtime and Linaria removes the CSS runtime. If the markup can be changed at runtime, how would you import additional stylesheets not included in Critical CSS? When I actually used it, it was helpful to inject Critical CSS, but splitting the rest of the stylesheets was rather inefficient because of the low cache hit rate. See the current implementation for details. |
Gatsby's mini-css-extract configuration does not split style chunks. As far as I know, It used to do it before, but now it rolls back and uses only 'all' chunk by default for compatibility issues when using plugins. So the option for chunk splitting is definitely a plugin's job, and most plugins don't do it at all. (ex. gatsby-plugin-styled-components, gatsby-plugin-emotion) |
This plugin separates a chunk for Linaria, separates the initial CSS injected into the , and asynchronously reloads whole chunk instead of the rest of the stylesheet. (This is why audit tools like Lighthouse complain about duplicate stylesheets) Maybe there are actually some better strategies for each use case, but making it customizable increases the complexity of the plugin. |
Please help me to understand here!
As I know the improvements of Linaria over Styled components or Emotion are
And Gatsbyjs is static site generator that optimize static assets at build time, so it generate style components CSS at build time.
So the my question is Why we need to use Linaria with gatsbyjs?
The text was updated successfully, but these errors were encountered: