Unverified Commit 4642591d authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

Mark React Compiler integration as stable (#84220)

parent 3f75ff69
......@@ -91,6 +91,7 @@ pub struct NextConfig {
pub experimental: ExperimentalConfig,
pub images: ImageConfig,
pub page_extensions: Vec<RcStr>,
pub react_compiler: Option<ReactCompilerOptionsOrBoolean>,
pub react_production_profiling: Option<bool>,
pub react_strict_mode: Option<bool>,
pub transpile_packages: Option<Vec<RcStr>>,
......@@ -816,7 +817,6 @@ pub struct ExperimentalConfig {
web_vitals_attribution: Option<Vec<RcStr>>,
server_actions: Option<ServerActionsOrLegacyBool>,
sri: Option<SubResourceIntegrity>,
react_compiler: Option<ReactCompilerOptionsOrBoolean>,
cache_components: Option<bool>,
use_cache: Option<bool>,
root_params: Option<bool>,
......@@ -1634,7 +1634,7 @@ impl NextConfig {
#[turbo_tasks::function]
pub fn react_compiler_options(&self) -> Vc<OptionalReactCompilerOptions> {
let options = &self.experimental.react_compiler;
let options = &self.react_compiler;
let options = match options {
Some(ReactCompilerOptionsOrBoolean::Boolean(true)) => {
......
---
title: reactCompiler
description: Enable the React Compiler to automatically optimize component rendering.
version: experimental
---
Next.js includes support for the [React Compiler](https://react.dev/learn/react-compiler), a tool designed to improve performance by automatically optimizing component rendering. This reduces the need for manual memoization using `useMemo` and `useCallback`.
Next.js includes support for the [React Compiler](https://react.dev/learn/react-compiler/introduction), a tool designed to improve performance by automatically optimizing component rendering. This reduces the need for manual memoization using `useMemo` and `useCallback`.
Next.js includes a custom performance optimization written in SWC that makes the React Compiler more efficient. Instead of running the compiler on every file, Next.js analyzes your project and only applies the React Compiler to relevant files. This avoids unnecessary work and leads to faster builds compared to using the Babel plugin on its own.
......@@ -20,15 +19,13 @@ To use it, install the `babel-plugin-react-compiler`:
npm install babel-plugin-react-compiler
```
Then, add `experimental.reactCompiler` option in `next.config.js`:
Then, add `reactCompiler` option in `next.config.js`:
```ts filename="next.config.ts" switcher
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
experimental: {
reactCompiler: true,
},
reactCompiler: true,
}
export default nextConfig
......@@ -37,9 +34,7 @@ export default nextConfig
```js filename="next.config.js" switcher
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
reactCompiler: true,
},
reactCompiler: true,
}
module.exports = nextConfig
......@@ -53,10 +48,8 @@ You can configure the compiler to run in "opt-in" mode as follows:
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
experimental: {
reactCompiler: {
compilationMode: 'annotation',
},
reactCompiler: {
compilationMode: 'annotation',
},
}
......@@ -66,10 +59,8 @@ export default nextConfig
```js filename="next.config.js" switcher
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
reactCompiler: {
compilationMode: 'annotation',
},
reactCompiler: {
compilationMode: 'annotation',
},
}
......
......@@ -482,14 +482,14 @@ export default async function getBaseWebpackConfig(
(appDir || pagesDir)!,
dev,
isClient,
config.experimental?.reactCompiler,
config.reactCompiler,
codeCondition.exclude
)
const reactCompilerLoader = babelLoader
? undefined
: getReactCompilerLoader(
config.experimental?.reactCompiler,
config.reactCompiler,
dir,
isNodeOrEdgeCompilation,
codeCondition.exclude,
......
......@@ -458,19 +458,7 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
testProxy: z.boolean().optional(),
defaultTestRunner: z.enum(SUPPORTED_TEST_RUNNERS_LIST).optional(),
allowDevelopmentBuild: z.literal(true).optional(),
reactCompiler: z.union([
z.boolean(),
z
.object({
compilationMode: z
.enum(['infer', 'annotation', 'all'])
.optional(),
panicThreshold: z
.enum(['none', 'critical_errors', 'all_errors'])
.optional(),
})
.optional(),
]),
reactDebugChannel: z.boolean().optional(),
staticGenerationRetryCount: z.number().int().optional(),
staticGenerationMaxConcurrency: z.number().int().optional(),
......@@ -655,6 +643,17 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
poweredByHeader: z.boolean().optional(),
productionBrowserSourceMaps: z.boolean().optional(),
publicRuntimeConfig: z.record(z.string(), z.any()).optional(),
reactCompiler: z.union([
z.boolean(),
z
.object({
compilationMode: z.enum(['infer', 'annotation', 'all']).optional(),
panicThreshold: z
.enum(['none', 'critical_errors', 'all_errors'])
.optional(),
})
.optional(),
]),
reactProductionProfiling: z.boolean().optional(),
reactStrictMode: z.boolean().nullable().optional(),
reactMaxHeadersLength: z.number().nonnegative().int().optional(),
......
......@@ -476,10 +476,10 @@ export interface ExperimentalConfig {
* Set this to `false` to disable the automatic configuration of the babel loader when a Babel
* configuration file is present. This option is enabled by default.
*
* If this is set to `false`, but `experimental.reactCompiler` is `true`, the built-in Babel will
* If this is set to `false`, but `reactCompiler` is `true`, the built-in Babel will
* still be configured, but any Babel configuration files on disk will be ignored. If you wish to
* use React Compiler with a different manually-configured `babel-loader`, you should disable both
* this and `experimental.reactCompiler`.
* this and `reactCompiler`.
*/
turbopackUseBuiltinBabel?: boolean
......@@ -678,12 +678,6 @@ export interface ExperimentalConfig {
*
*/
serverComponentsExternalPackages?: string[]
/**
* Enable experimental React compiler optimization.
* Configuration accepts partial config object to the compiler, if provided
* compiler will be enabled.
*/
reactCompiler?: boolean | ReactCompilerOptions
/**
* When enabled, in dev mode, Next.js will send React's debug info through the
......@@ -1099,6 +1093,13 @@ export interface NextConfig {
*/
productionBrowserSourceMaps?: boolean
/**
* Enable {@link https://nextjs.org/docs/app/api-reference/config/next-config-js/reactCompiler React Compiler in Next.js}.
* Configuration accepts partial config object of the Compiler.
* If provided, the Compiler will be enabled.
*/
reactCompiler?: boolean | ReactCompilerOptions
/**
* Enable react profiling in production
*
......@@ -1374,6 +1375,7 @@ export const defaultConfig = Object.freeze({
excludeDefaultMomentLocales: true,
serverRuntimeConfig: {},
publicRuntimeConfig: {},
reactCompiler: undefined,
reactProductionProfiling: false,
reactStrictMode: null,
reactMaxHeadersLength: 6000,
......@@ -1507,7 +1509,6 @@ export const defaultConfig = Object.freeze({
static: 300,
},
allowDevelopmentBuild: undefined,
reactCompiler: undefined,
reactDebugChannel: false,
staticGenerationRetryCount: undefined,
serverComponentsHmrCache: true,
......
......@@ -664,6 +664,13 @@ function assignDefaultsAndValidate(
configFileName,
silent
)
warnOptionHasBeenMovedOutOfExperimental(
result,
'reactCompiler',
'reactCompiler',
configFileName,
silent
)
if ((result.experimental as any).outputStandalone) {
if (!silent) {
......@@ -1812,19 +1819,11 @@ function enforceExperimentalFeatures(
if (
process.env.__NEXT_ENABLE_REACT_COMPILER === 'true' &&
// We do respect an explicit value in the user config.
(config.experimental.reactCompiler === undefined ||
(isDefaultConfig && !config.experimental.reactCompiler))
(config.reactCompiler === undefined ||
(isDefaultConfig && !config.reactCompiler))
) {
config.experimental.reactCompiler = true
if (configuredExperimentalFeatures) {
addConfiguredExperimentalFeature(
configuredExperimentalFeatures,
'reactCompiler',
true,
'enabled by `__NEXT_ENABLE_REACT_COMPILER`'
)
}
config.reactCompiler = true
// TODO: Report if we enable non-experimental features via env
}
if (
......
......@@ -123,14 +123,14 @@ export function eventCliSession(
pagesDir: event.pagesDir,
staticStaleTime: nextConfig.experimental.staleTimes?.static ?? null,
dynamicStaleTime: nextConfig.experimental.staleTimes?.dynamic ?? null,
reactCompiler: Boolean(nextConfig.experimental.reactCompiler),
reactCompiler: Boolean(nextConfig.reactCompiler),
reactCompilerCompilationMode:
typeof nextConfig.experimental.reactCompiler !== 'boolean'
? (nextConfig.experimental.reactCompiler?.compilationMode ?? null)
typeof nextConfig.reactCompiler !== 'boolean'
? (nextConfig.reactCompiler?.compilationMode ?? null)
: null,
reactCompilerPanicThreshold:
typeof nextConfig.experimental.reactCompiler !== 'boolean'
? (nextConfig.experimental.reactCompiler?.panicThreshold ?? null)
typeof nextConfig.reactCompiler !== 'boolean'
? (nextConfig.reactCompiler?.panicThreshold ?? null)
: null,
}
return [{ eventName: EVENT_VERSION, payload }]
......
......@@ -2,9 +2,7 @@
* @type {import('next').NextConfig}
*/
const nextConfig = {
experimental: {
reactCompiler: true,
},
reactCompiler: true,
reactProductionProfiling: true,
}
......
import { nextTestSetup, FileRef } from 'e2e-utils'
import { assertHasRedbox, retry } from 'next-test-utils'
import { assertHasRedbox } from 'next-test-utils'
import { join } from 'path'
import stripAnsi from 'strip-ansi'
......@@ -46,13 +46,6 @@ describe.each(['default', 'babelrc'] as const)(
},
})
it('should show an experimental warning', async () => {
await retry(() => {
expect(next.cliOutput).toContain('Experiments (use with caution)')
expect(stripAnsi(next.cliOutput)).toContain('✓ reactCompiler')
})
})
it('should memoize Components', async () => {
const browser = await next.browser('/')
......
module.exports = {
experimental: {
reactCompiler: true
}
reactCompiler: true
}
\ No newline at end of file
module.exports = {
experimental: {
reactCompiler: {
compilationMode: 'annotation',
panicThreshold: 'critical_errors'
}
reactCompiler: {
compilationMode: 'annotation',
panicThreshold: 'critical_errors'
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment