Skip to content

Infer filter as a mixed readonly array method#36392

Open
raashish1601 wants to merge 1 commit intofacebook:mainfrom
raashish1601:codex/compiler-local-mutation-filter
Open

Infer filter as a mixed readonly array method#36392
raashish1601 wants to merge 1 commit intofacebook:mainfrom
raashish1601:codex/compiler-local-mutation-filter

Conversation

@raashish1601
Copy link
Copy Markdown

Summary

  • infer .filter property loads as the MixedReadonly array method shape
  • preserve the existing noAlias callback behavior for untyped props arrays using .filter
  • add a regression fixture for local mutation inside a filter callback in useMemo

Why

When items comes from untyped props, items.filter was inferred as a generic function, so the local-mutation validator treated the callback as potentially escaping through the filtered result. The MixedReadonly model already defines .filter as a built-in array method with noAlias; this change lets that model apply to .filter property loads from untyped values.

Fixes #31569.

Test Plan

  • corepack yarn workspace snap run snap --update --pattern local-mutation-in-filter-usememo --sync
  • corepack yarn workspace snap run snap --pattern local-mutation-in-filter-usememo --sync
  • corepack yarn workspace babel-plugin-react-compiler run lint -- --quiet
  • corepack yarn prettier

Note: corepack yarn workspace snap run snap --pattern "{local-mutation-in-filter-usememo,noAlias-filter-on-array-prop}" --sync showed the new fixture passing; noAlias-filter-on-array-prop only failed on CRLF/LF snapshot text in this Windows checkout with identical generated code.

@meta-cla meta-cla Bot added the CLA Signed label May 2, 2026
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.

[Compiler Bug]: False positive local mutation warning inside filter

1 participant