Skip to content

React Compiler generates erroneous code when an app contains a component named Symbol #35379

@devuxer

Description

@devuxer

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/#N4Igzg9grgTgxgUxALhAejQAgMIwQQwBcFN9M4IBbABwgDsE7DM79KEATTAZQE9KARhAA2AHToAzKHTiEAlvR78hwgBQBKTMHGZMeQrDqYAPBzkA3AHwBJUpVJLBI8lVoMmxtGasBucQF9xcQxMAFUwEjlmOSMAQWpqcQQAD1oYZg4ECXwoYWYpGXlFeOoNLR09BAMYI1UK3VMLS3rdEwALAEZLACUCWRxXOWEEGEwAISgAc0xe6hgIDihZBTpPTuajVoa+J2FMNA2tz29DzHU-On8QABoQCkk5SZQQORoIdMxCXmoSYEwABWEUxiAHlqEU6GBMP5MBJ5vYAOQCfACBDCAC01CBkxi6Lw+Fk6IoNCGIy8cjAhARF3Eqm0mwwxOoQyIKwAsgsEMhMKIQPhhGIQAFMGBWWAJHIEFDAcC6GCIWBzjdwG0IAB3axMEasYRgFDZXUIfxAA

Repro steps

  1. Configure a React app to run React Compiler.
  2. Create a component named Symbol.
  3. Run the app.

The issue relates to the fact that React Compiler generates output with a call to Symbol.for. As shown in the playground link, if a component is in scope with the name Symbol, the compiler-generated code tries to call the for method on the React component rather than globalThis.Symbol. This results in the runtime error "Symbol.for is not a function".

How often does this bug happen?

Every time

What version of React are you using?

19.2.3

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