Compiler adoption, configuration, and directives
React Compiler can be rolled out gradually. You do not need to enable it across an entire production application in one step.
Start with simple configurationβ
For React 19, the normal starting point is intentionally small:
module.exports = {
plugins: ['babel-plugin-react-compiler'],
};
Most applications should avoid advanced configuration until a concrete rollout or compatibility need appears.
Compilation modesβ
React Compiler supports different selection strategies.
'use memo' is compiled.Infer modeβ
[
'babel-plugin-react-compiler',
{ compilationMode: 'infer' }
]
Use normal React naming conventions so components and Hooks are recognisable to tooling.
Annotation modeβ
[
'babel-plugin-react-compiler',
{ compilationMode: 'annotation' }
]
Then opt selected functions in:
function ProductGrid({ products }) {
'use memo';
return products.map(product => (
<ProductCard key={product.id} product={product} />
));
}
Annotation mode is useful when a mature codebase wants to validate Compiler behavior feature by feature.
'use memo'β
'use memo' explicitly opts a function into compilation where the current mode supports that control.
Use it sparingly. It is mainly useful for:
- annotation-mode rollout;
- controlled experiments;
- deliberate override of inference behavior.
'use no memo'β
'use no memo' opts a function out of Compiler optimization.
function ThirdPartyBridge() {
'use no memo';
return <LegacyWidget />;
}
This is useful for:
- isolating incompatible code;
- debugging behavior differences;
- temporarily excluding a known migration hotspot.
Treat it as an escape hatch with an owner and reasonβnot a permanent way to ignore Rules-of-React violations.
Function-level vs module-level directivesβ
Directives can control individual functions or, where supported by the current Compiler contract, a module scope.
Compiler diagnostics belong before rollout expansionβ
Modern eslint-plugin-react-hooks exposes Rules-of-React and Compiler-related diagnostics.
Do not add 'use no memo' merely to silence a correctness bug.
Gating and staged exposureβ
A production rollout may enable Compiler output for a controlled user, route, package, or deployment segment depending on the surrounding build/deployment architecture.
The exact gating mechanism depends on framework and deployment tooling.
Do not use directives to fight conventionsβ
If a component is misnamed or a Hook does not follow React conventions, fix the design rather than forcing compilation with directives.
The goal is maintainable React code that tooling can understand naturally.
Preserve manual memoization during migrationβ
Do not combine βenable Compilerβ and βremove every useMemo/useCallback/memoβ into one change.
Split them:
- enable Compiler;
- verify behavior and diagnostics;
- measure performance;
- remove manual memoization separately where justified.
This makes regressions easier to isolate.
Decision guideβ
Production rollout checklistβ
- current compiler/plugin versions are pinned;
- eslint diagnostics are active in CI;
- migration scope is explicit;
- existing manual memoization is preserved initially;
- tests cover behavior across compiled paths;
- production monitoring can compare releases;
- opt-outs have documented reasons;
- rollout can be narrowed without reverting unrelated product work.
Common mistakesβ
- enabling broad compilation and deleting manual memoization in the same change;
- adding
'use memo'everywhere; - using
'use no memo'to hide impure code; - skipping ESLint diagnostics;
- assuming Compiler coverage equals performance success;
- rolling out without a comparison or rollback path.
Interview questionsβ
Junior: What does 'use memo' do?
Mid-level: Why might annotation mode be useful in a mature codebase?
Senior: Design a Compiler migration plan for a legacy application with third-party libraries, manual memoization, CI linting, and gradual production exposure.