Skip to content

[compiler] Allow recursive useEffectEvent callbacks#36464

Open
yudin-s wants to merge 1 commit into
facebook:mainfrom
yudin-s:fix-use-effect-event-recursive-reference
Open

[compiler] Allow recursive useEffectEvent callbacks#36464
yudin-s wants to merge 1 commit into
facebook:mainfrom
yudin-s:fix-use-effect-event-recursive-reference

Conversation

@yudin-s
Copy link
Copy Markdown

@yudin-s yudin-s commented May 13, 2026

Summary

Fixes #34888.

The mutation inference pass was treating recursive references to a function returned from useEffectEvent as a use-before-declaration of the hoisted context variable. This happened because the scan for hoisted context accesses did not distinguish the declaration's initializer from true prior accesses, and it also continued to consider references after the StoreContext Const initialization as early reads.

This tracks initialized hoisted context declarations while finding early accesses and treats self-references through a useEffectEvent initializer as safe. The existing invalid setState-before-declaration case remains covered.

How did you test this change?

  • corepack yarn prettier --check packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/allow-recursive-useEffectEvent.tsx
  • corepack yarn build from compiler/packages/babel-plugin-react-compiler
  • corepack yarn snap:build from compiler
  • node ../snap/dist/main.js test --worker-threads false --pattern allow-recursive-useEffectEvent showed 1 Tests, 1 Passed, 0 Failed before local snap runner shutdown error Farm is ended, no more calls can be done to it
  • node ../snap/dist/main.js test --worker-threads false --pattern error.invalid-hoisting-setstate showed 1 Tests, 1 Passed, 0 Failed before the same local snap runner shutdown error

@meta-cla meta-cla Bot added the CLA Signed label May 13, 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]: Recursive functions seem to confuse the compiler

1 participant