-
Notifications
You must be signed in to change notification settings - Fork 47.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Compiler Bug]: Should support hooks named with symbols: use$, use_ #32473
Comments
+++ |
Hi @jmeistrich, thanks for reporting! React Compiler needs to be very correct in its custom hook callsite analysis. This is because (1) under-detection leads to memoization of hooks and undefined behavior (as you're currently experiencing) and (2) false positives result in incorrect mutability analysis (i.e. anything flowing into a hook is considered "frozen" as hooks are pure). Both of these can lead to serious bugs, and we're currently erroring on the side of preferring under-detection (which is much simpler to catch). Would LegendApp be open to renaming |
Hi @mofeiZ, thanks for the detailed response! I am trying to make Legend State 100% compatible and and correct with Compiler and all of the React rules, so I'll change it from I understand the reasoning for trying to prevent false positives. But I'm curious what false positives are avoided by not allowing If the constraint is "Functions whose names start with use" that suggests that any valid JavaScript function name thats starts with "use" would work, including the two symbols valid in function names ( |
What kind of issue is this?
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: LegendApp/legend-state#477I 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
The text was updated successfully, but these errors were encountered: