Security News
Python Overtakes JavaScript as Top Programming Language on GitHub
Python becomes GitHub's top language in 2024, driven by AI and data science projects, while AI-powered security tools are gaining adoption.
eslint-plugin-ssr-friendly
Advanced tools
ESLint plugin that detects incorrect use of DOM globals in order to properly do SSR
ESLint plugin that detects incorrect use of DOM globals properties in your code in order to properly do Server-Side-Rendering.
npm i --dev eslint-plugin-ssr-friendly
Then add these to your eslintrc configuration:
{
"plugins": ["ssr-friendly"],
"extends": ["plugin:ssr-friendly/recommended"]
}
no-dom-globals-in-module-scope
Disallow use of DOM globals in module and global scope,
as this will break any import/require
in a NodeJS environment.
To fix it, wrap it in a function that will call when on client-side.
Please note that we can't detect if you're still calling this function without
properly checking upfront if typeof window !== "undefined"
.
const retina = devicePixelRatio > 2;
const isRetina = () => devicePixelRatio >= 2;
no-dom-globals-in-constructor
Disallow use of DOM globals in class constructors, as this will break SSR if you're instantiating this class as singleton or you're rendering this component.
To fix it, move this statement in a initOnBrowser()
like-method or componentDidMount()
if you're using React.
Please note that we can't detect if you're still calling this function in your constructor without
properly checking upfront if typeof window !== "undefined"
.
class myClass {
constructor() {
document.title = "Otto";
}
}
class myClass {
componentDidMount() {
document.title = "Otto";
}
}
no-dom-globals-in-react-cc-render
Disallow use of DOM globals in render() method of a React class-component, as this will break SSR if you're rendering this component.
To fix it, move this statement to componentDidMount()
Please note that we can't detect if you're still calling this function in your constructor without
properly checking upfront if typeof window !== "undefined"
.
class Header extends React.Component {
render() {
const width = window.innerWidth;
return <div style={{ width }} />;
}
}
class Header extends React.Component {
componentDidMount() {
this.setState({ width: window.innerWidth });
}
render() {
return <div style={{ width }} />;
}
}
no-dom-globals-in-react-fc
Disallow use of DOM globals in the render-cycle of a React FC, as this will break SSR if you're rendering this component.
To fix it, move this statement into a useEffect())
const Header = () => {
window.addEventListener("resize", () => {});
return <div />;
};
const Header = () => {
useEffect(() => {
window.addEventListener("resize", () => {});
}, []);
return <div />;
};
FAQs
ESLint plugin that detects incorrect use of DOM globals in order to properly do SSR
The npm package eslint-plugin-ssr-friendly receives a total of 59,286 weekly downloads. As such, eslint-plugin-ssr-friendly popularity was classified as popular.
We found that eslint-plugin-ssr-friendly demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Python becomes GitHub's top language in 2024, driven by AI and data science projects, while AI-powered security tools are gaining adoption.
Security News
Dutch National Police and FBI dismantle Redline and Meta infostealer malware-as-a-service operations in Operation Magnus, seizing servers and source code.
Research
Security News
Socket is tracking a new trend where malicious actors are now exploiting the popularity of LLM research to spread malware through seemingly useful open source packages.