The gating option enables conditional compilation, allowing you to control when optimized code is used at runtime.
{
gating: {
source: 'my-feature-flags',
importSpecifierName: 'shouldUseCompiler'
}
}Reference
gating
Configures runtime feature flag gating for compiled functions.
Type
{
source: string;
importSpecifierName: string;
} | nullDefault value
null
Properties
source: Module path to import the feature flag fromimportSpecifierName: Name of the exported function to import
Caveats
- The gating function must return a boolean
- Both compiled and original versions increase bundle size
- The import is added to every file with compiled functions
Usage
Basic feature flag setup
- Create a feature flag module:
// src/utils/feature-flags.js
export function shouldUseCompiler() {
// your logic here
return getFeatureFlag('react-compiler-enabled');
}- Configure the compiler:
{
gating: {
source: './src/utils/feature-flags',
importSpecifierName: 'shouldUseCompiler'
}
}- The compiler generates gated code:
// Input
function Button(props) {
return <button>{props.label}</button>;
}
// Output (simplified)
import { shouldUseCompiler } from './src/utils/feature-flags';
const Button = shouldUseCompiler()