Skip to content

Feat/adds the no-window-eq-undefined ESLint rule to @docusaurus/eslint-plugin.#11858

Closed
webdevpraveen wants to merge 4 commits intofacebook:mainfrom
webdevpraveen:feat/eslint-no-window-eq-undefined
Closed

Feat/adds the no-window-eq-undefined ESLint rule to @docusaurus/eslint-plugin.#11858
webdevpraveen wants to merge 4 commits intofacebook:mainfrom
webdevpraveen:feat/eslint-no-window-eq-undefined

Conversation

@webdevpraveen
Copy link
Copy Markdown

Summary

Adds the no-window-eq-undefined ESLint rule to @docusaurus/eslint-plugin.

Closes #6472

Motivation

Using typeof window !== 'undefined' is a common pattern for SSR escape hatching in React apps, but it is the wrong approach in Docusaurus. Docusaurus provides purpose-built APIs — useIsBrowser() and ExecutionEnvironment.canUseDOM — which integrate correctly with its SSR/pre-rendering pipeline.

This implements the no-window-eq-undefined rule originally proposed in #6472. (The string-literal-i18n-messages rule from the same issue was implemented in #7206, but this rule was never added.)

Changes

  • packages/eslint-plugin/src/rules/no-window-eq-undefined.ts — new rule implementation
  • packages/eslint-plugin/src/rules/__tests__/no-window-eq-undefined.test.ts — rule tests
  • packages/eslint-plugin/src/index.ts — register rule + add to all config
  • website/docs/api/misc/eslint-plugin/no-window-eq-undefined.mdx — documentation page
  • website/docs/api/misc/eslint-plugin/README.mdx — add to supported rules table

Test Plan

yarn jest packages/eslint-plugin — all tests pass including new rule tests.

Rule Behavior

Flagged (incorrect pattern)

if (typeof window !== 'undefined') { ... }
const isBrowser = typeof window === 'undefined';
'undefined' !== typeof window  // reversed operands also caught

Not flagged (correct Docusaurus patterns)

import useIsBrowser from '@docusaurus/useIsBrowser';
const isBrowser = useIsBrowser();

import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
if (ExecutionEnvironment.canUseDOM) { ... }

@meta-cla
Copy link
Copy Markdown

meta-cla bot commented Mar 29, 2026

Hi @webdevpraveen!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 29, 2026

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit 98aba4f
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/69c96b16596cbc0008148415
😎 Deploy Preview https://deploy-preview-11858--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@slorber
Copy link
Copy Markdown
Collaborator

slorber commented Mar 30, 2026

Thanks, but I don't think we need this, at least not in the form it is currently designed

Please respect my comment here, you clearly saw it and still sent a PR anyway: #6472 (comment)

Also, please disclose AI usage as requested in our contribution guidelines

@slorber slorber closed this Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create ESLint plugin rules to enforce best Docusaurus practices

2 participants