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]: Consider the dispatch fn from useActionState and useFormState to be non-reactive #29674

Closed
1 of 4 tasks
josephsavona opened this issue May 30, 2024 · 13 comments
Closed
1 of 4 tasks

Comments

@josephsavona
Copy link
Contributor

What kind of issue is this?

  • React Compiler core (the JS output is incorrect, or your app works incorrectly after optimization)
  • babel-plugin-react-compiler (build issue installing or using the Babel plugin)
  • eslint-plugin-react-compiler (build issue installing or using the eslint plugin)
  • react-compiler-healthcheck (build issue installing or using the healthcheck script)

Link to repro

https://playground.react.dev/#N4Igzg9grgTgxgUxALhAMygOzgFwJYSYAEAwhALYAOhCmOAFAJRHAA6xRchYORA2gENcBTAGUcAnAgA0RACZ4wlSXAAWAQWGEAukQC8RKGASb8hcZIRMA3OyKduvPmggxyFqbIVKVqgGKu5LoGRggBbh5WjLaYdg6YPETmUABG5Hg4piL6REz6AHwscfbeyjhqWYQ2cQC+MXFcCbzJaRnh5Dl5eoVsHCWKZWrt1Rw17HEwCDiwxAA8ARBJYqnpmVqYesAtq5WYNUuiK22Bm9vHbvsA9PkxNSA1QA

Repro steps

Align with #29665, considering the dispatch function returned by useActionState and useFormState to be non-reactive.

This requires updating REACT_APIS in Globals.ts to define these hooks and their return type, and annotate the dispatch function as non-reactive. See the definition for useState as an example.

How often does this bug happen?

Every time

What version of React are you using?

19

@josephsavona josephsavona added Type: Bug Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug Component: Optimizing Compiler good first issue and removed Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug labels May 30, 2024
@josephsavona
Copy link
Contributor Author

josephsavona commented May 30, 2024

For anyone interested in contributing: This requires updating Globals.ts and ObjectShape.ts:

  • Define new types for the return value of these hooks, similar to how the type of BuiltInUseStateId is defined in ObjectShape.ts
  • Define the hooks themselves (using those new types as the return types) in Globals.ts, similar to how useState is defined in the REACT_APIs variable.
  • Add fixtures that demonstrate usage of these apis, similar to the playground above.

@eps1lon
Copy link
Collaborator

eps1lon commented May 31, 2024

dispatch from useReducer is also considered reactive at the moment as far as I can tell: https://playground.react.dev/#N4Igzg9grgTgxgUxALhAMygOzgFwJYSYAEAwhALYAOhCmOAFAJRHAA6xRchYORA2jwCGOBABoiAEzxhKwuAAsAukQC8RKGAQAlBBKiIYTANzt2RTt16EAylABG5PLzVNVAPhZnzk6bJwLjLwBfU0wvGAQcWGIAHgAxCAgiG3tHHBVgFIcnIKIAejcTTCCQIKA

@hieudo-dev
Copy link
Contributor

Hi everyone! I'd love to give this one a try if it's not assigned already

@josephsavona
Copy link
Contributor Author

@hieudo-dev sure, give it a try!

@RaphaelTaibi
Copy link

Hello, I am a junior developer. Is it possible for me to participate in this issue? Open source React is very important to me. It's a library that I particularly love since I discovered it. I wish to improve my skills and learn more about it.
Thank you for taking the time to respond to me.

@PRANJALI-SANKPAL
Copy link

Is this issue resolved ? If not i want to work on it

josephsavona pushed a commit that referenced this issue Jun 5, 2024
… is non-reactive (#29705)

Summary
The dispatch function from useReducer is stable, so it is also non-reactive.

the related PR: #29665
the related comment: #29674 (comment)

I am not sure if the location of the new test file is appropriate😅.

How did you test this change?
Added the specific test compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useReducer-returned-dispatcher-is-non-reactive.expect.md.
github-actions bot pushed a commit that referenced this issue Jun 5, 2024
… is non-reactive (#29705)

Summary
The dispatch function from useReducer is stable, so it is also non-reactive.

the related PR: #29665
the related comment: #29674 (comment)

I am not sure if the location of the new test file is appropriate😅.

How did you test this change?
Added the specific test compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useReducer-returned-dispatcher-is-non-reactive.expect.md.

DiffTrain build for commit 704aeed.
@josephsavona
Copy link
Contributor Author

The fix has been merged, thanks!

@eps1lon
Copy link
Collaborator

eps1lon commented Jun 7, 2024

@josephsavona The merged PR only added support for useReducer. The PR for adressing useActionState and useFormState is still open. I guess the remaining discussion topic is if we want to support the old name. I'd say that's worth it considering it was shipped in Next.js but maybe worth bringing up in the next sync?

@josephsavona josephsavona reopened this Jun 10, 2024
@josephsavona
Copy link
Contributor Author

ooops sorry about that!

@PRANJALI-SANKPAL
Copy link

So issue is reopened? Should I start working on it?

@josephsavona
Copy link
Contributor Author

See #29758

@kmr-ankitt
Copy link

can i give it a try?

@josephsavona
Copy link
Contributor Author

Landed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants