Repository navigation
Open
Labels
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
react-compiler-runtime loses a component's render counter registration after its first update. This example calls useRenderCounter directly and displays the registered counter count after each update.
import { useEffect, useRef, useState } from 'react';
import { renderCounterRegistry, useRenderCounter } from 'react-compiler-runtime';
export function App() {
const [updates, setUpdates] = useState(0);
const log = useRef(null);
useRenderCounter('App');
useEffect(() => {
// Observe after the counter's effect without triggering another render.
const registered = renderCounterRegistry.get('App')?.size ?? 0;
log.current.textContent += `Updates: ${updates}; registered counters: ${registered}\n`;
}, [updates]);
return (
<main>
<h1>React Compiler render counter registration</h1>
<p>Expected: one registered counter while this component is mounted.</p>
<button onClick={() => setUpdates(updates + 1)}>Update component: {updates}</button>
<pre ref={log} aria-live="polite" />
</main>
);
}Steps To Reproduce
- Follow the reproduction setup instructions to start the app.
- Open the URL printed in the terminal and click Update component: 0.
The current behavior
The registered counter count drops from 1 to 0 while the component remains mounted:
Updates: 0; registered counters: 1
Updates: 1; registered counters: 0
Reproduced in Chrome on macOS.
The expected behavior
Updates: 0; registered counters: 1
Updates: 1; registered counters: 1
How often does this bug happen?
Every time
What version of React are you using?
19.3.1
What version of React Compiler are you using?
Reacted by Nahied Bangladesh
Activity