Skip to content

Gatsby Plugin Fix FOUC is a plugin that solves flash of unstyled content

License

Notifications You must be signed in to change notification settings

bicstone/gatsby-plugin-fix-fouc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gatsby Plugin Fix FOUC

Test CI status Linter CI status Publish CD status FOSSA Status Quality Gate Status DeepSource status codecov status npm downloads npm bundle size

Gatsby Plugin Fix FOUC is a plugin that solves flash of unstyled content.

Supports Gatsby v3 - v5

Screen records when plugin is used (note, used gif animation images)
Without Plugin With Plugin
Screen records that flicker is occurring during react hydrate. Screen records that no flickering occurs because the page is hidden.

How Does It Work

Adds a data attribute to the <body> element that hides the page until the initial render of Gatsby App is done on the client, so that the awful flicker is not shown to you.
This approach is also used by Google. Does not re-rendering and has no impact on performance and accessibility.

Trade-Off

Lighthouse scores will decrease. (First Contentful Paint, Largest Contentful Paint) as a result, it may affect SEO. (but, Cumulative Layout Shift scores improve.)
You can specify the width that does not hide the screen by setting minWidth.

Install

yarn add gatsby-plugin-fix-fouc

# or

npm install gatsby-plugin-fix-fouc

Usage

// gatsby-config.js

module.exports = {
  plugins: [`gatsby-plugin-fix-fouc`],
};

Advanced

// gatsby-config.ts

import { breakpoints } from "./src/themes";

import type { GatsbyConfig } from "gatsby";
import type { GatsbyPluginFixFoucRefOptions } from "gatsby-plugin-fix-fouc";

const config: GatsbyConfig = {
  plugins: [
    {
      resolve: `gatsby-plugin-fix-fouc`,
      options: {
        attributeName: "is-loading",
        minWidth: breakpoints.values.sm,
        timeout: 3000,
      } as GatsbyPluginFixFoucRefOptions,
    },
  ],
};

export default config;

Options

Property Type Default Description
attributeName string gatsby-plugin-fix-fouc-is-loading The data-* attribute name to be added.
minWidth number 0 The minimum width (px) of hides the page. If not set, hides regardless of width.
timeout number 4000 The time (milliseconds) of the timer should wait before shows the page as a fallback even if the initial render is not done.

Contributors

Thanks goes to these wonderful people (emoji key):


Oishi Takanori

🤔 💻 🚧 💬 📖 👀

LICENCE

MIT License

FOSSA Status