Skip to main content
Version: Canary 🚧

no-window-eq-undefined

Disallow typeof window !== "undefined" checks as an SSR escape hatch.

Rule details

In Docusaurus, using typeof window !== 'undefined' is not the recommended way to detect a browser environment. This check may not work correctly with Docusaurus's SSR/pre-rendering pipeline.

❌ Incorrect

if (typeof window !== 'undefined') {
// browser-only code
}

✅ Correct

Use the useIsBrowser() hook from @docusaurus/useIsBrowser inside React components:

import useIsBrowser from '@docusaurus/useIsBrowser';

function MyComponent() {
const isBrowser = useIsBrowser();
if (isBrowser) {
// browser-only code
}
}

Or use ExecutionEnvironment.canUseDOM from @docusaurus/ExecutionEnvironment outside React:

import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';

if (ExecutionEnvironment.canUseDOM) {
// browser-only code
}

Options

This rule has no options.