fix(immutability): exclude event handler params from props mutation check#1647
Merged
Rel1cx merged 3 commits intoRel1cx:mainfrom Mar 28, 2026
Merged
Conversation
…heck The `isPropsObject` check incorrectly treated the first parameter of any function as a React props object. This caused false positives when mutating DOM properties via event handler parameters like `e.currentTarget.value = ""`. The fix defers verification of the props-defining function to Program:exit, where the component/hook collector results are available, ensuring only parameters of actual components or hooks are flagged. Closes Rel1cx#1626 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@zerone0x is attempting to deploy a commit to the Rel1cx's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
623712a to
40d81f0
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the react/immutability ESLint rule logic to avoid false positives when mutating DOM element properties via event handler parameters (e.g. e.currentTarget.value = "") while preserving existing props/state mutation detection.
Changes:
- Replaces boolean
isPropsObjectlogic withgetPropsDefiningFunction, returning the parameter-defining function node (ornull). - Adds a
Program:exitverification step to ensure props-based violations originate from an actual component or hook function, preventing event-handler-parameter misclassification. - Adds valid test cases covering DOM
currentTargetmutations in both named and inline event handlers.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/plugins/eslint-plugin-react-x/src/rules/immutability/immutability.ts | Refines props-parameter detection by tracking the defining function and validating it against collected components/hooks at Program:exit. |
| packages/plugins/eslint-plugin-react-x/src/rules/immutability/immutability.spec.ts | Adds regression tests ensuring DOM event target mutations in handlers are not flagged as props/state mutations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
react/immutabilityflagged mutations of DOM element properties via event handler parameters (e.g.e.currentTarget.value = "") as props mutationsisPropsObjectto return the defining function node, which is then verified atProgram:exitto be an actual component or hook — event handler parameters are no longer misidentified as React propsCloses #1626
Test plan
vitest runon immutability spec)e.currentTarget.value = ""in named handler functionse.currentTarget.disabled = truein inline arrow handlers🤖 Generated with Claude Code