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 Bug]: Increment expression in for-loop loses assignment operation #29956

Closed
1 of 4 tasks
derekcicerone opened this issue Jun 19, 2024 · 4 comments
Closed
1 of 4 tasks
Labels
Component: Optimizing Compiler Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug Type: Bug

Comments

@derekcicerone
Copy link

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/#N4Igzg9grgTgxgUxALhAMygOzgFwJYSYAEAGgBQCURwAOsUWhDEWQDYI5F5EC8RADAG4uRADxEAjPyEi+3ANSSqwAL50VIFUA

Repro steps

In our repo we have code similar to the Playground link posted above which when compiled loses the assignment part of the increment expression.

The original code:

          for (
            let node: LexicalNode | null = selection.anchor.getNode();
            node && !$isRootNode(node);
            node = node.getParent()
          ) {

Compiled to this code:

        for (let node5 = selection.anchor.getNode(); node5 && !$isRootNode2(node5); node5.getParent()) {

Happy to provide additional information or context if needed, thanks!

How often does this bug happen?

Every time

What version of React are you using?

19.0.0-rc-f3e09d6328-20240612

@derekcicerone derekcicerone added Component: Optimizing Compiler Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug Type: Bug labels Jun 19, 2024
@josephsavona
Copy link
Contributor

Thanks for the bug report, we’ll take a look!

@Fnll
Copy link
Contributor

Fnll commented Jun 24, 2024

It seams that updateValue in for loop will be reassigned to LoadLocal even if it is originally a StoreLocal Reassign instruction at here.

can we simply use the original instruction's value just like how it's tackled for while loop at here?

@josephsavona
Copy link
Contributor

Fix landed, thanks for filing!

@derekcicerone
Copy link
Author

Thanks, that was quick!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Optimizing Compiler Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug Type: Bug
Projects
None yet
Development

No branches or pull requests

3 participants