Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
gatsby-plugin-js-fallback
Advanced tools
Gatsby plugin to fallback gracefully when JS is disabled on client side
Gatsby plugin to fallback gracefully when JS is disabled on client side.
// In your gatsby-config.js
module.exports = {
plugins: [
`gatsby-plugin-js-fallback`
// ... other plugins
]
};
Then in the React components/page that you would like to provide a fallback when JavaScript is disabled on client side:
import React from 'react';
import { useIsJsEnabled } from 'gatsby-plugin-js-fallback';
const GracefulPage = () => {
const isJsEnabled = useIsJsEnabled();
return isJsEnabled ? <MyFancyComponentThatNeedJs /> : <SimpleComponent />;
};
useIsJsEnabled
would returns false
, thus the pre-rendered HTML will contain the fallback UI that does not rely on JavaScript.useIsJsEnabled
would returns true
, then the UI that relies on JavaScript will be displayed.useIsJsEnabled
A custom hooks that only returns true
when your Gatsby site hydrate successfully on client side.
Sometimes, you want to introduce some components in your Gatsby site that rely heavily on JavaScript. However, this would cause your site non-usable when JavaScript is disabled on client side.
There are two approaches to deal with this:
This plugin allows you to implement second approach.
There may be content flash from the fallback UI to the enhanced UI at initial page/page refresh. This is because the pre-rendered HTML (that contains the fallback UI) will be displayed while the page is downloading all the js files and then detect if JS is enabled.
There is no solution to avoid this content flash at the moment. If you have any suggestion, raise an issue at let me know!
FAQs
Gatsby plugin to fallback gracefully when JS is disabled on client side
We found that gatsby-plugin-js-fallback demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.