Skip to content

[eslint-plugin-react-hooks] Ignore unreachable hooks in rules-of-hooks - #38449

Open
lazerg wants to merge 1 commit into
react:mainfrom
lazerg:fix/issue-38438-unreachable-hooks
Open

lazerg wants to merge 1 commit into
react:mainfrom
lazerg:fix/issue-38438-unreachable-hooks

Conversation

@lazerg

@lazerg lazerg commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Summary

rules-of-hooks kept one flat segment stack shared by every code path, and the code path analyzer doesn't fire onCodePathSegmentStart for unreachable segments. So a hook call after a throw or return was recorded against whatever was left on the stack. At the top level that was undefined, which crashed ESLint in onCodePathEnd. Inside a component it was the enclosing Program segment, which gave a false "called conditionally" error.

This keeps a separate segment stack per code path and skips hook calls when the current code path has no active segment, so unreachable hooks are ignored like the rule already intends.

Fixes #38438

How did you test this change?

Added two valid cases to ESLintRulesOfHooks-test.js (a top-level hook after throw, and a hook after an exhaustive return in a component). Both fail before the change and pass after it. yarn workspace eslint-plugin-react-hooks test and yarn typecheck pass.

@meta-cla meta-cla Bot added the CLA Signed label Nov 29, 2026
@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Comparing: edae846...58ebd81

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 7.35 kB 7.35 kB +0.05% 1.96 kB 1.96 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 628.58 kB 628.58 kB = 110.98 kB 110.98 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 7.36 kB 7.36 kB = 1.96 kB 1.96 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 699.69 kB 699.69 kB = 122.41 kB 122.41 kB
facebook-www/ReactDOM-prod.classic.js = 717.77 kB 717.77 kB = 125.46 kB 125.46 kB
facebook-www/ReactDOM-prod.modern.js = 708.11 kB 708.11 kB = 123.88 kB 123.88 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by sizebot against 58ebd81

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[eslint-plugin-react-hooks] rules-of-hooks crashes on top-level unreachable hooks and misreports unreachable hooks inside components

1 participant