question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What controls whether gatsby-plugin-sass inlines the resulting CSS?

See original GitHub issue

Summary

I have two different Gatsby projects that I believe to be as similar as they could be without being identical, but one of them is getting a FOUC when deployed on Netlify and the other isn’t. I think I’ve narrowed it down that the good one without FOUC is getting inline CSS like this (attached) but the other one isn’t:

Screen Shot 2020-02-11 at 10 13 58 PM

In the other project, I do not even see a style tag, weirdly enough! I can’t figure out what the difference is that is causing one to use inline styles on gatsby build and the other to not.

Relevant information

In both projects, I am importing the sass file like this, in the layout.js file:

import("./../stylesheets/index.sass")

Both updated to the latest packages, both with configs like what you see below.

File contents (if changed)

gatsby-config.js:

module.exports = {
  plugins: [
    `gatsby-plugin-react-helmet`,
    `gatsby-plugin-sass`,
    {
      resolve: "gatsby-source-wordpress",
      options: {
        baseUrl: "www.XXXXXXXXXXX.com",
        protocol: "https",
        auth: {},
        cookies: {},
        verboseOutput: false,
        perPage: 100,
        searchAndReplaceContentUrls: {},
        concurrentRequests: 10,
        includedRoutes: ["**/categories", "**/tags", "**/posts"],
        keepMediaSizes: true,
        normalizer: function({ entities }) {
          return entities
        },
      },
    },
  ],
}

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
wardpeetcommented, Feb 13, 2020

I think the problem is your import, can you switch

import("./../stylesheets/index.sass")

into

import "./../stylesheets/index.sass"

The difference between the two is that import() tells webpack to make this a async import so it will give you fouc.

1reaction
wardpeetcommented, Feb 13, 2020

More on this topic: https://webpack.js.org/guides/code-splitting/#dynamic-imports

Technically you should never use dynamic imports for css

Read more comments on GitHub >

github_iconTop Results From Across the Web

gatsby-plugin-sass
gatsby-plugin-sass Provides drop-in support for Sass/SCSS stylesheets Install How ... If you need to override the default options passed into css-loader .
Read more >
CSS Modules + Sass Setup for Gatsby - Mediacurrent
CSS Modules provides a familiar approach to working with Sass -- even if you're not well-versed in Gatsby. Here's how to get started....
Read more >
Gatsby puts all css in head - Stack Overflow
I've done a quick test with gatsby-plugin-split-css and it appears to give you the desired behaviour. However, I would use caution as you...
Read more >
Gatsby Changelog | 5.3.0
After the files are built, Gatsby will then stitch the resulting markup and JavaScript to the pages that include that shared component.
Read more >
How to Load Fonts in a Way That Fights FOUT and Makes ...
Choose a few nice-looking web-ready fonts, get the HTML or CSS code ... we'll also look at a Gatsby implementation as well as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found