Skip to content

Clarify immutability lint does not report method-call mutations on state - #8759

Open
officialasishkumar wants to merge 1 commit into
reactjs:mainfrom
officialasishkumar:docs/immutability-lint-method-mutations
Open

officialasishkumar wants to merge 1 commit into
reactjs:mainfrom
officialasishkumar:docs/immutability-lint-method-mutations

Conversation

@officialasishkumar

Copy link
Copy Markdown

Fixes #8758

The immutability page listed items.push(4), setItems(items.sort()) and the todos.push() troubleshooting example as violations the rule reports. The compiler doesn't infer the types of state values, so it only errors on mutations it can prove, such as user.name = 'Bob'; method calls on state produce no diagnostic (see react/react#35157).

Changes:

  • Keep the property assignment as the only "Invalid" example.
  • Add a note that method-call mutations like push()/sort() on state aren't reported yet but are still bugs.
  • Add a non-mutating sort to the valid examples.
  • Mention in the troubleshooting section that the linter doesn't currently report push() on state.

…on state

The immutability rule page listed items.push(), items.sort() and the
todos.push() troubleshooting example as violations the rule catches.
The compiler does not infer the types of state values, so it only
reports mutations it can prove (such as property assignment) and
produces no diagnostic for these method calls.

Keep the property assignment as the invalid example, add a note that
method-call mutations on state are not detected yet, and show a
non-mutating sort in the valid examples.
@github-actions

Copy link
Copy Markdown

Size changes

Details

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

This branch was successfully deployed

1 active deployment
Preview — 9eed07a1 Deployed Nov 13, 2026 by vercel[bot]
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.

[Bug]: immutability lint page lists push() and sort() mutations that the rule does not report

1 participant