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]: Using for loop for array of strings #30627

Closed
1 of 4 tasks
saul-atomrigs opened this issue Aug 7, 2024 · 3 comments · Fixed by #30631
Closed
1 of 4 tasks

[Compiler]: Using for loop for array of strings #30627

saul-atomrigs opened this issue Aug 7, 2024 · 3 comments · Fixed by #30631
Labels
Component: Optimizing Compiler Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug Type: Bug

Comments

@saul-atomrigs
Copy link
Contributor

saul-atomrigs commented Aug 7, 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

Repro steps

Hello @gsathya ,

I was wondering if the for ... in was intended instead of for ... of.

I think for ... of is more recommended for array of strings (Array<string>) like in this case.

Thanks!

How often does this bug happen?

Every time

What version of React are you using?

18.3.1

@saul-atomrigs saul-atomrigs added Component: Optimizing Compiler Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug Type: Bug labels Aug 7, 2024
@gsathya
Copy link
Contributor

gsathya commented Aug 7, 2024

I agree for.. of is generally better but this seems fine. Instead of these one-offs, I wonder if we should just simply add a lint rule to simply disallow for.. in in the code base.

@guillaumebrunerie
Copy link

But doesn't for ... in iterate over the keys, as opposed to for ... of which iterates over the values? So in this case, prefix will be "0", "1", "2" etc., no matter which strings the array contains.

@poteto
Copy link
Member

poteto commented Aug 7, 2024

yeah, this looks like it might be a bug. would either of you like to open a PR to fix?

But doesn't for ... in iterate over the keys, as opposed to for ... of which iterates over the values? So in this case, prefix will be "0", "1", "2" etc., no matter which strings the array contains.

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

Successfully merging a pull request may close this issue.

4 participants