Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[compiler] Check ref access in useState initializer function #32506

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ggyongyi
Copy link

@ggyongyi ggyongyi commented Mar 3, 2025

Summary

This PR fixes #31418 .

The compiler did not throw an error when a useState initializer function accessed a ref value during render.

How did you test this change?

I added new tests using useState initializer functions to the babel-plugin-react-compiler and eslint-plugin-react-compiler packages and ran yarn test.

I also built the compilers and checked they worked in a small project with babel and the vs code eslint plugin.
The babel-plugin-react-compiler logged an error due to the ref access:
babel-plugin

The eslint-plugin-react-compiler also reported an error:
eslint-plugin

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]: Does not check for ref access in setState initial value function
2 participants