GithubHelp home page GithubHelp logo

bicstone / gatsby-plugin-fix-fouc Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 1.0 12.48 MB

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

Home Page: https://www.npmjs.com/package/gatsby-plugin-fix-fouc

License: MIT License

TypeScript 100.00%
fouc gatsby gatsby-plugin hacktoberfest javascript react ssg ssr

gatsby-plugin-fix-fouc's Introduction

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

gatsby-plugin-fix-fouc's People

Contributors

bicstone avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

fossabot

gatsby-plugin-fix-fouc's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • chore(deps): update devdependencies (@types/node, cypress)

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/lint-pr-title.yml
  • amannn/action-semantic-pull-request v5
.github/workflows/linter.yml
  • actions/checkout v4
  • actions/setup-node v4
.github/workflows/njsscan-analysis.yml
  • actions/checkout v4
  • github/codeql-action v3
.github/workflows/publish-latest.yml
  • actions/checkout v4
  • actions/setup-node v4
.github/workflows/publish-next.yml
  • actions/checkout v4
  • actions/setup-node v4
.github/workflows/sonarcloud.yml
  • actions/checkout v4
.github/workflows/test.yml
  • actions/checkout v4
  • actions/setup-node v4
  • codecov/codecov-action v4
nodenv
.node-version
  • node 20.16.0
npm
e2e/package.json
  • cypress 13.13.2
  • gatsby 5.13.7
  • start-server-and-test 2.0.5
  • node 20.16.0
e2e/plugins/gatsby-plugin-fix-fouc/package.json
package.json
  • @babel/cli 7.24.8
  • @babel/core 7.25.2
  • @testing-library/dom 10.4.0
  • @testing-library/react 16.0.0
  • @types/jest 29.5.12
  • @types/node 20.14.15
  • @types/react 18.3.3
  • @types/react-dom 18.3.0
  • @typescript-eslint/eslint-plugin 7.18.0
  • @typescript-eslint/parser 7.18.0
  • all-contributors-cli 6.26.1
  • babel-preset-gatsby-package 3.13.1
  • eslint 8.57.0
  • eslint-config-love 47.0.0
  • eslint-config-prettier 9.1.0
  • eslint-config-standard 17.1.0
  • eslint-plugin-import 2.29.1
  • eslint-plugin-n 17.10.2
  • eslint-plugin-promise 6.6.0
  • gatsby 5.13.7
  • gatsby-plugin-utils 4.13.1
  • husky 9.1.4
  • jest 29.7.0
  • jest-environment-jsdom 29.7.0
  • prettier 3.3.3
  • react 18.3.1
  • react-dom 18.3.1
  • ts-jest 29.2.4
  • ts-node 10.9.2
  • typescript 5.5.4
  • gatsby ^3 || ^4 || ^5
  • node 20.16.0
  • yarn 4.4.0
  • yarn 4.4.0

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.