What kind of issue is this?
Link to repro
https://github.com/JonasDoe/FailingReactCompiler
Repro steps
When I combine optional chaining with a try/catch pattern, doSomething isn't stable anymore and the useEffect callback (hence: the logging) is invoked multiple times.
export const MinimalFailingCase: React.FC = () => {
const [count, setCount] = useState(0);
const { doSomething } = useMinimalFailing();
useEffect(() => {
console.log('[MinimalFailing] Effect ran - doSomething changed'); // this is logged on every button click
}, [doSomething]);
return (
<p>Count: {count}</p>
<button onClick={() => setCount(c => c + 1)}>Increment</button>
);
};
const useClient= ()=> {
const [client] = useState({ doThing: async () => 'result' });
return client;
}
const useMinimalFailing =()=> {
const client = useClient();
const doSomething = async () => {
try {
// ❌ Optional chaining - compiler doesn't memoize
const result = await client?.doThing();
return { type: 'ok' as const, result };
} catch {
return { type: 'err' as const };
}
};
return { doSomething };
}
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?
babel-plugin-react-compiler@1.0.0, if you mean that
What kind of issue is this?
Link to repro
https://github.com/JonasDoe/FailingReactCompiler
Repro steps
When I combine optional chaining with a
try/catchpattern,doSomethingisn't stable anymore and theuseEffectcallback (hence: the logging) is invoked multiple times.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?
babel-plugin-react-compiler@1.0.0, if you mean that