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]: Linter complains about ref current access during render when returning array with Typescript's as const #31864

Closed
1 of 4 tasks
valtism opened this issue Dec 20, 2024 · 1 comment · Fixed by #31871

Comments

@valtism
Copy link

valtism commented Dec 20, 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/#N4Igzg9grgTgxgUxALhASwLYAcIwC4AEwBUYCAwgIYA21ARpXANYA0JZASggGZukIBlPJTwICAXwLcYEDAQA6IGAkZ5FAbnkA7bQgAeOfFKha4eNBC3tBaAF4IAFAEoi2ggTiWwhANoATTAQtMAtgtjI8ABFA4NCwAF0CAF5rIRFHYDd3AgB3ND88AAtkAgAGFiz3QoQ0AHNCvBLyrPEnTR0rDy9CLGUANwtSAHk6Mhg+hBhk6y5uZ3asz2DCOFI8WVnp-ipaBmYHBy0IPwQXJIA+V073NG4CB16EAegwEbGJmAA6VZhlLTwXJlrtlHs9hqNJh9vrA-nhPgEwEstAgzPNKiD+oNXhDxpNob8goQUiYTtw0Mi-O1shJtOjbvcjicAPyfRkIAAqAE8sGIknyCAA5Y4IT4AUQAMqKALKigXsgD6AqGkVFgPR7iW3gIEBxH2myJyBC4IXsb0hkwOPkJME58TOlyB1Op9Ic1s5BAAZB6CG7PnRcCcYAAhCB6AR2U5XJ1OzWEYjk6jkmz2Ep5AqFNh0agQZjhlMEap1BoSZLq6M+-42v0ByYhsMRnyleILYHRiLRDBBEJeBzENNFNiF+qEVpU8viMuj2mt7W6vE696ONltMugrFm3FfH6w6YL80wMfuCedcRsHx2lvuZR4WBWHyrbwbHhsAKd2JeZvaY8gcRAA

Repro steps

  1. Copy the code above to a typescript file with react compiler linting.
  2. Add as const to the end of the line returning [customRef, dimensions].
  3. The linter will suddenly complain about Ref values (the current property) may not be accessed during render.

How often does this bug happen?

Every time

What version of React are you using?

18.2.0

What version of React Compiler are you using?

19.0.0-beta-201e55d-20241215

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

Thanks for the bug report!

@josephsavona josephsavona removed the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Dec 20, 2024
josephsavona added a commit to josephsavona/react that referenced this issue Dec 20, 2024
We report a false positive for the combination of a ref-accessing function placed inside an array which is they type-cast. Here we teach ref validation about type casts. I also tried other variants like `return ref as const` but those already worked.

Closes facebook#31864
josephsavona added a commit that referenced this issue Dec 20, 2024
We report a false positive for the combination of a ref-accessing
function placed inside an array which is they type-cast. Here we teach
ref validation about type casts. I also tried other variants like
`return ref as const` but those already worked.

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

Successfully merging a pull request may close this issue.

2 participants