Gatsby: Delay when loading CSS with Gatbsy

Created on 13 Nov 2018  路  20Comments  路  Source: gatsbyjs/gatsby

Description

When I load for the first time the gatbsy blog, I have a delay before CSS is loading. I think 300ms...
Whatever the browser is, it always do this.

It renders once before CSS is applied and 300ms after is rendered well.

Why?

Demo here

On page loading

capture d ecran 2018-11-13 a 10 09 32

After 300ms

capture d ecran 2018-11-13 a 10 09 45

Environment

  System:
    OS: macOS 10.14
    CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 8.12.0 - /usr/local/bin/node
    npm: 6.4.1 - /usr/local/bin/npm
  Browsers:
    Chrome: 70.0.3538.77
    Safari: 12.0
  npmPackages:
    gatsby: ^2.0.24 => 2.0.43 
    gatsby-image: ^2.0.15 => 2.0.20 
    gatsby-plugin-lodash: ^3.0.1 => 3.0.2 
    gatsby-plugin-manifest: ^2.0.5 => 2.0.8 
    gatsby-plugin-offline: ^2.0.6 => 2.0.13 
    gatsby-plugin-react-helmet: ^3.0.0 => 3.0.1 
    gatsby-plugin-sharp: ^2.0.7 => 2.0.12 
    gatsby-plugin-sitemap: ^2.0.1 => 2.0.2 
    gatsby-source-prismic: ^2.0.0 => 2.1.0 
    gatsby-transformer-sharp: ^2.1.4 => 2.1.8 
  npmGlobalPackages:
    gatsby-cli: 2.4.5

File contents (if changed)

gatsby-config.js: N/A
package.json: N/A
gatsby-node.js: N/A
gatsby-browser.js: N/A
gatsby-ssr.js: N/A

needs more info

Most helpful comment

If you're using a css-in-js library, you need to install its corresponding gatsby plugin to ensure that the css for pages is extracted and added to the generated HTML as otherwise, css isn't added until after the JS loads which causes the delay you see.

See https://www.gatsbyjs.org/packages/gatsby-plugin-styled-components/?=styled

All 20 comments

@Steffi3rd is this during develop or after build when you are serving it?

It's on build.

On develop, I have a blank page very very fast before it renders well.

@Steffi3rd can you provide us with a minimal reproduction repo for this issue?

@Steffi3rd if you can, provide a repo so that this issue can be further investigated and we can provide better assistance with this.

@steffi3rd if you are using a CSS library then it's better to put the cdn link in html.js. let us access to your repo for further assistance! 馃榿馃憤

@Steffi3rd if you are using a CSS library then it's better to put the cdn link in html.js. let us access to your repo for further assistance! 馃榿馃憤

I use Styled Component, is there a problem with this?

@Steffi3rd if you can, provide a repo so that this issue can be further investigated and we can provide better assistance with this.

@Steffi3rd if you can, provide a repo so that this issue can be further investigated and we can provide better assistance with this.

@Steffi3rd if you can, provide a repo so that this issue can be further investigated and we can provide better assistance with this.

The url is : https://edgebase.github.io/blog/

@Steffi3rd no...that's the url for the production build, the full blow website address...What i and other people before me asked is if you could provide a repo as in a github repository address, where you have your code hosted so that i and other people can check the code and see what is the issue and how we can assist you on resolving your issue. If you cannot provide that address because your code is otherwise private or protected by a company, provide us with an alternative, namely a dummy github url which replicates the exact issue you're experiencing with the library, so that me and other people like me can see what is the actual problem and aid you in fixing it

If you're using a css-in-js library, you need to install its corresponding gatsby plugin to ensure that the css for pages is extracted and added to the generated HTML as otherwise, css isn't added until after the JS loads which causes the delay you see.

See https://www.gatsbyjs.org/packages/gatsby-plugin-styled-components/?=styled

If you're using a css-in-js library, you need to install its corresponding gatsby plugin to ensure that the css for pages is extracted and added to the generated HTML as otherwise, css isn't added until after the JS loads which causes the delay you see.

See https://www.gatsbyjs.org/packages/gatsby-plugin-styled-components/?=styled

Yeaaaah ! I installed gatsby-plugin-styled-component ! It finally works! Thank you @KyleAMathews

Just found your answer on a another post : https://github.com/gatsbyjs/gatsby/issues/5366

I installed gatsby-plugin-styled-components but am still getting this issue. You can see the css getting moved on the homepage, where the articles all start center aligned. https://jonsjournal.com/

It does NOT happen on the local develop version.

Repo here: https://github.com/j10sanders/jonsjournal

Possibly also relevant -- I've noticed that setting localStorage is also not working on the deployed build version, but is working on the local develop one.

Any suggestions?
Thanks

Same problem, I also installed gatsby-plugin-styled-components but I still get the delay before the CSS being loaded...

I've got the same issue with styled-components and gatsby-plugin-styled-components.
Anyone found a fix for this one?

+1, same issue here with the styled-components plugin correctly installed. Has anyone found a solution?

gatsby-render-layout-slow

Repo: https://github.com/sky172839465/yusong.io

+1 same issue, in production Layout component render from wrapPageElement very slow,
I found a workaround from @alexanderwe 's solution, thanks!

I have same problem, installed gatsby-plugin-styled-components styled-components babel-plugin-styled-components
Any solution to the problem?

Same problem here too!

I got the same problem. Has anyone found a solution?

Check this commit, using gatsby-plugin-layout instead of wrapPageElement can solve the problem.

https://github.com/sky172839465/yusong.io/commit/34f03eebc3be06ef1135db1895a098b63749a229

I have the same problem on most of my Gastby projects and not fixed yet...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

timbrandin picture timbrandin  路  3Comments

dustinhorton picture dustinhorton  路  3Comments

mikestopcontinues picture mikestopcontinues  路  3Comments

3CordGuy picture 3CordGuy  路  3Comments

theduke picture theduke  路  3Comments