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]: Can't handle Dynamic JavaScript Object Keys #29583

Closed
1 of 4 tasks
Y-Hui opened this issue May 24, 2024 · 3 comments
Closed
1 of 4 tasks

[Compiler Bug]: Can't handle Dynamic JavaScript Object Keys #29583

Y-Hui opened this issue May 24, 2024 · 3 comments
Labels
Component: Optimizing Compiler Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug Type: Bug

Comments

@Y-Hui
Copy link

Y-Hui commented May 24, 2024

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/#N4Igzg9grgTgxgUxALhAgdlAtgAgMoAuAhgVGDsADro75RyJhgBmUANgDTW0Cq6Y9Ri3ZcaOAEoIAVgjgEAlgDcEogL7VqCAB4AHCDAI5W6OfIg1CJMgBUiAcwAUOmBB1gAlBW4445sIeAcfytyVRwAXhxnVzANMV9+QwSCDENIqjFaAG1LUjAAOjxBBCZWNgBdZBwAHgBhCCw9dFSAQRwAegA+UVps3LJ8vgEGEuEKqrqGptSAIQ7u7z7iPPzJGVNlSpr6xvNU2vmenHV0bwT-HGI7QgBPNhKIr0ycHOWBopHS9i2AcgAjOwAWjsMAQGEBAEYAAxQnB-fQAEwQMDhiORwNB4IArDDLtoCBiwehAQB2GE-I5LEKDfjFL7jHD-IGghF4rQEgDuAAt5CkKYsXv0CmtZApNlUmYD9ER0HYEGzOTy+UcTt5QaQYDQHALqgilD42EQmAA5IhYBDhYBwNhgLQOH5XCmXey3e5gLLBPLldyqToC2hW8wpdAED1vMDlE69GrtPWKP1idzUVXoYymcw4HbTEMtByeDK0dWwGiUEAIiAldAOnBYEgpGClgDcyeoaYUGazexDMzzT0LCA1JbLFbAVcMtYI9abLdTUBM7ZoneaIdqvYLOCLmpwpfLlerE6nIGb6BOIFUQA

Repro steps

enum Status {
  Successful,
  Unsuccessful,
  Rejective,
}

const content = {
  [Status.Successful]: <ComponentA />,
  [Status.Unsuccessful]: <ComponentB />,
  [Status.Rejective]: <ComponentC />,
}

When writing the above code within the component, it fails to compile.
It gets an error like this

Todo: (BuildHIR::lowerExpression) Expected Identifier, got MemberExpression key in ObjectExpression (11:11)

How often does this bug happen?

Every time

What version of React are you using?

19

@Y-Hui Y-Hui added Component: Optimizing Compiler Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug Type: Bug labels May 24, 2024
@Y-Hui
Copy link
Author

Y-Hui commented May 24, 2024

It's worth noting that it won't compile in playground, but will skip compilation in the local project, which doesn't have any configuration items set for babel-plugin-react-compiler.

@josephsavona
Copy link
Contributor

josephsavona commented May 24, 2024

Thanks for posting! React Compiler supports a broad range of JavaScript (and TypeScript/Flow) syntax, but there are some syntax forms we don't yet support. Computed object expression keys is on the list of todos. We allowlist the syntax we intend to support and skip compiling functions that use unsupported syntax. The playground shows all errors, but as @Y-Hui noted if you use a function like this locally we'll just skip it without error (w default configuration, which is strongly recommended).

I'm going to close since this is a known todo and not a bug. Thanks again for posting!

@Y-Hui
Copy link
Author

Y-Hui commented May 25, 2024

Got it - thanks!

@Y-Hui Y-Hui closed this as completed May 25, 2024
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

2 participants