Skip to content

Preserve optional chains in exhaustive-deps suggestions#36411

Open
raashish1601 wants to merge 1 commit into
facebook:mainfrom
raashish1601:codex/exhaustive-deps-optional-chain-suggestion
Open

Preserve optional chains in exhaustive-deps suggestions#36411
raashish1601 wants to merge 1 commit into
facebook:mainfrom
raashish1601:codex/exhaustive-deps-optional-chain-suggestion

Conversation

@raashish1601
Copy link
Copy Markdown

Summary

Fixes #23248.

When the same dependency path is read through both optional and non-optional member expressions, the exhaustive-deps suggestion should keep the optional form. Dependency arrays are evaluated outside guarded blocks, so suggesting the non-optional form can introduce a render-time error while fixing an unrelated dependency.

Tests

  • corepack yarn --cwd packages/eslint-plugin-react-hooks jest ESLintRuleExhaustiveDeps-test --runInBand
  • corepack yarn --cwd packages/eslint-plugin-react-hooks typecheck
  • git diff --check

@meta-cla meta-cla Bot added the CLA Signed label May 5, 2026
Copy link
Copy Markdown

@codeCraft-Ritik codeCraft-Ritik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix! Preserving the optional form in exhaustive-deps suggestions avoids introducing unsafe render-time behavior while resolving dependency warnings.
Good catch on the dependency array semantics outside guarded execution paths 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

2 participants