Skip to main content

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.

A safe Compiler rollout is incremental
1Lint
2Fix correctness issues
3Compile a controlled scope
4Test
5Profile
6Expand

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.

Compilation mode controls which eligible functions are compiled
DEFAULT SHAPEinfer
Compiler identifies likely components and Hooks automatically.
OPT INannotation
Only code explicitly marked with 'use memo' is compiled.
BROADall
Compile eligible functions broadly, with opt-out available where needed.

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.
Directives are local overrides, not the architecture
Project/compiler configuration
Defines normal policy
Directive
Narrow exception or rollout control

'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.

Function-level
Best when one component/Hook needs an exception or controlled experiment.
Module-level
Affects a broader file surface; use intentionally because blast radius is larger.

Compiler diagnostics belong before rollout expansion​

Modern eslint-plugin-react-hooks exposes Rules-of-React and Compiler-related diagnostics.

1Lint finds violation / incompatible pattern
2Understand the correctness issue
3Fix or isolate
4Compiler coverage increases safely

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.

Rollout control should separate build readiness from user exposure
Compiler-enabled build
Controlled exposure
Broader rollout

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:

  1. enable Compiler;
  2. verify behavior and diagnostics;
  3. measure performance;
  4. remove manual memoization separately where justified.

This makes regressions easier to isolate.

Decision guide​

Which rollout strategy fits the codebase?
Modern codebase with strong Rules-of-React complianceStart with normal infer-mode integration
Large legacy codebase / cautious adoptionUse lint + smaller scopes or annotation mode
One incompatible component/library bridgeTemporarily opt out narrowly
Need confidence before full exposureUse release gating + profiling/observability

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.

Summary​

Compiler adoption is a controlled correctness-and-performance rollout
Rules-compliant code
Compiler scope
Safe production expansion

References​