Skip to content

[compiler] Allow refs in IntersectionObserver callbacks#36418

Open
raashish1601 wants to merge 1 commit intofacebook:mainfrom
raashish1601:codex/refs-intersection-observer
Open

[compiler] Allow refs in IntersectionObserver callbacks#36418
raashish1601 wants to merge 1 commit intofacebook:mainfrom
raashish1601:codex/refs-intersection-observer

Conversation

@raashish1601
Copy link
Copy Markdown

Summary

The refs lint rule reports a false positive when a ref-reading callback is passed to new IntersectionObserver(...) inside useMemo. The callback is stored by the browser observer and invoked later, not synchronously during render.

This routes NewExpression through the same effect-aware refs validation path used for function calls, then adds a typed IntersectionObserver constructor signature that treats the callback as frozen/read-only. Unknown constructors remain conservative and still report when passed a ref-reading callback.

Fixes #35982

How did you test this change?

  • corepack yarn --cwd packages/eslint-plugin-react-hooks build:compiler
  • corepack yarn --cwd packages/eslint-plugin-react-hooks jest ReactCompilerRuleTypescript-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
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.

Bug: react-hooks/refs false positive using IntersectionObserver

1 participant