Gatsby: [v2] CSS preloading observations

Created on 19 Jun 2018  Â·  6Comments  Â·  Source: gatsbyjs/gatsby

Description

Seeing a Chrome and Lighthouse warning related to CSS assets not being preloaded (correctly?) when using gatsby serve after upgrading to latest v2 beta releases.

Steps to reproduce

Upgraded to latest beta releases of Gatsby v2 as recommended in the v2 beta announcement blog.

Expected result

No console warning or recommendation from Lighthouse. (compared to v1)

Actual result

Chrome

screen shot 2018-06-18 at 8 11 36 pm

screen shot 2018-06-18 at 8 13 06 pm

Lighthouse

screen shot 2018-06-18 at 8 12 23 pm

Environment

$ ./node_modules/.bin/gatsby info --clipboard

  System:
    OS: macOS High Sierra 10.13.5
    CPU: x64 Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 8.9.4 - /usr/local/bin/node
    Yarn: 1.7.0 - /usr/local/bin/yarn
    npm: 5.6.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 67.0.3396.87
    Firefox: 60.0.1
    Safari: 11.1.1
  npmPackages:
    gatsby: ^2.0.0-beta.1 => 2.0.0-beta.1
    gatsby-cli: ^1.1.58 => 1.1.58
    gatsby-plugin-google-analytics: ^1.0.20-10 => 1.0.20-10
    gatsby-plugin-react-helmet: ^2.0.12-7 => 2.0.12-7
    gatsby-plugin-sitemap: ^1.2.14-10 => 1.2.14-10
    gatsby-plugin-typography: ^2.0.1-11 => 2.0.1-11

File contents (if changed)

gatsby-config.js: N/A
package.json

$ git diff package.json
diff --git a/package.json b/package.json
index efa965a..ca4a395 100644
--- a/package.json
+++ b/package.json
@@ -31,12 +31,12 @@
     "enzyme-adapter-react-16": "^1.1.1",
     "eslint": "^4.19.1",
     "eslint-plugin-react": "^7.7.0",
-    "gatsby": "next",
+    "gatsby": "^2.0.0-beta.1",
     "gatsby-cli": "^1.1.58",
-    "gatsby-plugin-google-analytics": "next",
-    "gatsby-plugin-react-helmet": "next",
-    "gatsby-plugin-sitemap": "next",
-    "gatsby-plugin-typography": "next",
+    "gatsby-plugin-google-analytics": "^1.0.20-10",
+    "gatsby-plugin-react-helmet": "^2.0.12-7",
+    "gatsby-plugin-sitemap": "^1.2.14-10",
+    "gatsby-plugin-typography": "^2.0.1-11",
     "glob": "^7.1.2",
     "jest": "^22.4.3",
     "prop-types": "^15.6.1",

gatsby-node.js: N/A
gatsby-browser.js: N/A
gatsby-ssr.js: N/A

bug

All 6 comments

Ah nice catch! Yeah, we inline the critical CSS so shouldn't also preload it. I don't use CSS really so didn't catch this. I believe the logic should be if style.rel is preload, we just inline and if prefetch we add prefetch and don't inline.

Could you make a PR for this?

https://github.com/gatsbyjs/gatsby/blob/a3cb2566c79525d2575f07f0a96e597e388d899c/packages/gatsby/src/cache-dir/static-entry.js#L238-L264

Thanks for the quick feedback and pointer @KyleAMathews ! Will give it my best shot!

Hmm... this change has led to new layout jumps on the first page load when using v2.

For those of us using CSS, the v1 inlining resulted in a seamless first load experience (all styles implemented immediately), while the new page jumps on load resulting from not inlining the styles are less ideal.

Can we please either revert to always inlining the styles (like v1) or add the option to do so when a particular site would benefit from that approach?

I just noticed that while the styles are not inlined in development, they do appear to be inlined in production. Is this the intended behaviour?

Sorry if I'm missing something obvious here... I'd love to jump to the v2 beta, but just want to make sure that client sites will still have their styles inlined in production.

I've moved my follow-up discussion to #6211.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ferMartz picture ferMartz  Â·  3Comments

timbrandin picture timbrandin  Â·  3Comments

brandonmp picture brandonmp  Â·  3Comments

signalwerk picture signalwerk  Â·  3Comments

3CordGuy picture 3CordGuy  Â·  3Comments