facebook / react

The library for web and native user interfaces.
https://react.dev
MIT License
229.28k stars 46.95k forks source link

[Compiler Bug]: null reference exception if you assume a value is not null in a callback (which can be valid) #31551

Open lukpsaxo opened 2 hours ago

lukpsaxo commented 2 hours ago

What kind of issue is this?

Link to repro

https://playground.react.dev/#N4Igzg9grgTgxgUxALhAMygOzgFwJYSYAEAKgmDgBTBEC2AhgJ4BGCAclADacA0RAvgEoiwADrEicQhUnMiAXiJQwCAML1uzenADWlSsPkA+EeKLmiaTNSIAPZHSasO3AHS2BggNxmBfANoMLOxcvAC63uK+MAg4sMRBzqFEAPxEADxgAA70xAD0Jg7pACZ4AG5EhKqceLrywHDM-EQFPpj8IPxAA

Repro steps

Similiar to https://github.com/facebook/react/issues/31550 but with useCallback and no external deps.

You seem to assume that accessing x.y is safe in the render method if it is safe in a callback.

How often does this bug happen?

Every time

What version of React are you using?

18.3.1

What version of React Compiler are you using?

19.0.0-beta-a7bf2bd-20241110

lukpsaxo commented 2 hours ago

Similiar to https://github.com/facebook/react/issues/31269 but that is fixed on the playground and this is not.