The React Compiler (babel-plugin-react-compiler, stable since 1.0 in October 2025) runs at build time. It analyzes each component and hook, works out which values depend on which props, state and context, and rewrites the function so each value, callback and JSX element is cached and recomputed only when its inputs change.
The effect is useMemo and useCallback around everything, plus the job of memo: when a parent re-renders, an unchanged child gets back the same element object, and React skips it. It can memoize where hooks can't, such as after an early return. It targets updates, not the first render.
Caching is only safe for code that gives the same result anyway, so it requires the Rules of React:
- Pure render. No side effects, no
Date.now()orMath.random(), no reading or writingref.current, no reassigning variables outside the component. - Immutability. Props, state, hook arguments and values passed to JSX are never mutated.
- Rules of Hooks and naming. By default it compiles only functions named like components (PascalCase, returning JSX or calling hooks) or hooks (
use…, calling hooks).
When it detects a violation, it bails out of that one function and leaves it as written; the rest of the file is still compiled. By default the bail-out is silent: the build passes and prints nothing. The same analysis ships as lint rules in eslint-plugin-react-hooks 7 (refs, purity, globals, set-state-in-render and more), which is where you see the problems. A violation it can't detect is compiled, and behaviour can change.
Escape hatches: "use no memo" opts one function out; compilationMode: 'annotation' compiles only functions marked "use memo". useMemo and useCallback stay for precise control, such as keeping an effect dependency stable.