Skip to content

[Compiler Bug]: React Compiler bug: closure is lost in useEffect when component is returned from a factory (causes ReferenceError: <identifier> is not defined) #36128

@budarin

Description

@budarin

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://github.com/budarin/react-compiler-bug-repro

Repro steps

  1. Create a Vite React TS project with React Compiler enabled.
  2. Use a factory function that returns a component and captures injected dependencies (e.g. showWelcomeNotification) in a closure.
  3. Inside the returned component, call the injected dependency in a useEffect.
  4. Run the dev server; a runtime ReferenceError occurs.

How often does this bug happen?

Every time

What version of React are you using?

19.2.4

What version of React Compiler are you using?

1.0.0

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