-
Notifications
You must be signed in to change notification settings - Fork 50.7k
Open
Labels
Status: UnconfirmedA potential issue that we haven't yet confirmed as a bugA potential issue that we haven't yet confirmed as a bugType: Bug
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-hooks (build issue installing or using the eslint plugin)
- react-compiler-healthcheck (build issue installing or using the healthcheck script)
Link to repro
Repro steps
See the link for playground.
Basically, the ref-in-render rule doc states that this very specific access is allowed:
Example 1:
// ✅ Lazy initialization of ref value
function Component() {
const ref = useRef(null);
// Initialize only once on first use
if (ref.current === null) {
ref.current = expensiveComputation(); // OK - lazy initialization
}However, if expensiveComputation is impure, it still fires.
Example 2:
if (ref.current === null) {
ref.current = Date.now(); // purity ruleAnd of course, useState(() => Date.now()) is fine. The react docs say
// It only runs once when the hook is called, so only the current date at the
// time the hook is called is set first.
Between those three, I'd expect my second example to be valid, but it's not?
How often does this bug happen?
Every time
What version of React are you using?
19.0.1
What version of React Compiler are you using?
1.0.0
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Status: UnconfirmedA potential issue that we haven't yet confirmed as a bugA potential issue that we haven't yet confirmed as a bugType: Bug