这是indexloc提供的服务,不要输入任何密码
Skip to content

[Compiler Bug]: function are not memorized correctly. #35122

@promer94

Description

@promer94

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-hooks (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/#N4Igzg9grgTgxgUxALhAMygOzgFwJYSYAEAKgmDgIwAUAlEcADrFFyEVEDaCAHgA54YCADREwCHAFF+ghAF0iAXiJRxAZRwBDHAmoBWWsyIrxktGgS5qdJQD4GR463Y4i+ALYIYSsRICSmDowAG6aADbW9Ir2TCxOvlIyQtZ8QsFR9qkIwUQAtESUhnFEAL6ilAAMVUXxeGhE1LwCQkqKyhX0sfHGcGEImjABQaERHl41TiWOxkI4sMQ20ax9A0NeI9RjMBNlXE2ychNsmByEAMJheHAA1j6LMdPOJxB9AHRhEADm1ADkeGDSZoIAAmP1E-0BsmBO0cxw4EKSIJ8+xabXajlm8yIAB5gXgcudLjdFMBCVdriVlpowGAAHKaTyKRggHQ8HC5ITA3J6KrM2zAFEIErYgD0eOCtmYJRAwhAxzQeE+KBAeHcfAgMFcOAAnnwEAwiAAFMJQT54TAAeT4+HYpSIaBgEHcRB+ACNNK6EGFcnwTWbMBz+rhcmw1Xg+jAxf8cD8ANzMZjULpEEUi0MCMLaAiYACyEGBCGQRGZ4TCzKlYizYAV5CNfvNVptJ1osZl4AAFhAAO5rGCYcJgFBoAdCoA

Repro steps

Link to the code that reproduces this issue

https://github.com/promer94/incorrect-memo-fn-nextjs

To Reproduce

  1. build the application with next build
  2. start the application with next start
  3. click the numbers to see the console log
function Test1() {
    const [expire, setExpire] = useState(5)
    useEffect(() => {
        const timer = setInterval(() => {
            setExpire((prev) => prev - 1)
        }, 1000)
        if (expire === 0) {
            clearInterval(timer)
        }
        return () => clearInterval(timer)
    }, [expire])
    const onClick = () => {
        console.log('isExpired', isExpired)
    }
    const isExpired = expire === 0
    return <div onClick={onClick} className="text-red-500">{expire}</div>
}

The onclick function should be able to access the latest value of isExpired

How often does this bug happen?

Every time

What version of React are you using?

19.2.0

What version of React Compiler are you using?

1.0.0 would cause this bug

But ^19.1.0-rc.3 works correctly

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bugType: Bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions