Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bicstone/gatsby-plugin-fix-fouc
Gatsby Plugin Fix FOUC is a plugin that solves flash of unstyled content
https://github.com/bicstone/gatsby-plugin-fix-fouc
fouc gatsby gatsby-plugin hacktoberfest javascript react ssg ssr
Last synced: 12 days ago
JSON representation
Gatsby Plugin Fix FOUC is a plugin that solves flash of unstyled content
- Host: GitHub
- URL: https://github.com/bicstone/gatsby-plugin-fix-fouc
- Owner: bicstone
- License: mit
- Created: 2022-08-24T13:38:52.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-29T10:01:56.000Z (9 months ago)
- Last Synced: 2024-05-01T17:11:48.757Z (8 months ago)
- Topics: fouc, gatsby, gatsby-plugin, hacktoberfest, javascript, react, ssg, ssr
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/gatsby-plugin-fix-fouc
- Size: 9.19 MB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# Gatsby Plugin Fix FOUC
[![Test CI status](https://github.com/bicstone/gatsby-plugin-fix-fouc/actions/workflows/test.yml/badge.svg)](https://github.com/bicstone/gatsby-plugin-fix-fouc/actions/workflows/test.yml)
[![Linter CI status](https://github.com/bicstone/gatsby-plugin-fix-fouc/actions/workflows/linter.yml/badge.svg)](https://github.com/bicstone/gatsby-plugin-fix-fouc/actions/workflows/linter.yml)
[![Publish CD status](https://github.com/bicstone/gatsby-plugin-fix-fouc/actions/workflows/publish-latest.yml/badge.svg)](https://github.com/bicstone/gatsby-plugin-fix-fouc/actions/workflows/publish-latest.yml)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fbicstone%2Fgatsby-plugin-fix-fouc.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fbicstone%2Fgatsby-plugin-fix-fouc?ref=badge_shield)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=bicstone_gatsby-plugin-fix-fouc&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=bicstone_gatsby-plugin-fix-fouc)
[![DeepSource status](https://deepsource.io/gh/bicstone/gatsby-plugin-fix-fouc.svg/?label=active+issues&token=o00wTEndphJPK3wZIrU6C0OZ)](https://deepsource.io/gh/bicstone/gatsby-plugin-fix-fouc/?ref=repository-badge)
[![codecov status](https://codecov.io/gh/bicstone/gatsby-plugin-fix-fouc/branch/main/graph/badge.svg?token=ACW4cNAmjT)](https://codecov.io/gh/bicstone/gatsby-plugin-fix-fouc)
[![npm downloads](https://img.shields.io/npm/dm/gatsby-plugin-fix-fouc.svg?&logo=npm)](https://www.npmjs.com/package/gatsby-plugin-fix-fouc)
![npm bundle size](https://img.shields.io/bundlephobia/min/gatsby-plugin-fix-fouc)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.](./docs/readme-images/without-plugin-movie.gif) | ![Screen records that no flickering occurs because the page is hidden.](./docs/readme-images/with-plugin-movie.gif) |## How Does It Work
Adds a data attribute to the `` 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](https://developers.google.com/optimize/). 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
```bash
yarn add gatsby-plugin-fix-fouc# or
npm install gatsby-plugin-fix-fouc
```## Usage
```js
// gatsby-config.jsmodule.exports = {
plugins: [`gatsby-plugin-fix-fouc`],
};
```## Advanced
```ts
// gatsby-config.tsimport { 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](https://allcontributors.org/docs/en/emoji-key)):
Oishi Takanori
🤔 💻 🚧 💬 📖 👀
## LICENCE
MIT License
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fbicstone%2Fgatsby-plugin-fix-fouc.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fbicstone%2Fgatsby-plugin-fix-fouc?ref=badge_large)