react / react/react

[Compiler Bug]: Should support hooks named with symbols: use$, use_

Open
#32,473 4 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Component: React Compiler Status: Unconfirmed Type: Bug
Dominant language
JavaScript
Stars
251k
Forks
51.4k
Avg merge
2d 4h
Merged PRs (30d)
53

Description

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://github.com/vladmiller/legend-state-react-compiler-bug

Repro steps

isHookName checks for valid hook names and requires alphanumeric names. I believe it should also support $ and _ since those are valid characters in JavaScript function names.

In Legend State we have a hook named use$ to consume observables, which I had thought would be compatible with Compiler. So this is currently breaking Legend State with the Compiler enabled. See issue: https://github.com/LegendApp/legend-state/issues/477

I think the isHookName regexp should be changed to this to match valid function names in JavaScript.

/^use[A-Z0-9_$]*$/

Thanks 🙏

How often does this bug happen?

Every time

What version of React are you using?

19.0.0

What version of React Compiler are you using?

19.0.0-beta-e1e972c-20250221

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts at isHookName, then reproduce the issue with the linked Legend State example. Check how hook names containing $ and _ are classified and verify that the compiler handles use$ and use_ correctly without breaking existing hook-name behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
compilers, frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.