Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/next/src/build/babel/loader/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { webpack } from 'next/dist/compiled/webpack/webpack'
import type { JSONValue } from '../../../server/config-shared'
import type { Span } from '../../../trace'

export interface NextJsLoaderContext extends webpack.LoaderContext<{}> {
Expand All @@ -17,7 +18,7 @@ export interface NextBabelLoaderBaseOptions {
/**
* Custom plugins to be added to the generated babel options.
*/
reactCompilerPlugins?: Array<any>
reactCompilerPlugins?: Array<JSONValue>

/**
* Paths that the loader should not apply the react-compiler to.
Expand Down
44 changes: 23 additions & 21 deletions packages/next/src/build/get-babel-loader-config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path'
import type { ReactCompilerOptions } from '../server/config-shared'
import type { JSONValue, ReactCompilerOptions } from '../server/config-shared'
import type { NextBabelLoaderOptions } from './babel/loader/types'

function getReactCompiler() {
Expand All @@ -15,27 +15,26 @@ function getReactCompiler() {
}

const getReactCompilerPlugins = (
options: boolean | ReactCompilerOptions | undefined,
isServer: boolean
) => {
if (!options || isServer) {
maybeOptions: boolean | ReactCompilerOptions | undefined,
isServer: boolean,
isDev: boolean
): undefined | JSONValue[] => {
if (!maybeOptions || isServer) {
return undefined
}

const compilerOptions = typeof options === 'boolean' ? {} : options
if (options) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flagged by Vade: https://github.com/vercel/next.js/pull/84062/files#r2371737820

We already bailed out earlier on falsy options so no need to check again.

return [
[
getReactCompiler(),
{
// https://react.dev/reference/react-compiler/panicThreshold
panicThreshold: 'none',
...compilerOptions,
},
],
]
const defaultOptions: ReactCompilerOptions = isDev
? {
// TODO: enable `environment.enableNameAnonymousFunctions`Ï
}
: {}
const options: ReactCompilerOptions =
typeof maybeOptions === 'boolean' ? {} : maybeOptions
const compilerOptions: JSONValue = {
...defaultOptions,
...options,
}
return undefined
return [[getReactCompiler(), compilerOptions]]
}

const getBabelLoader = (
Expand Down Expand Up @@ -67,7 +66,8 @@ const getBabelLoader = (
hasJsxRuntime: true,
reactCompilerPlugins: getReactCompilerPlugins(
reactCompilerOptions,
isServer
isServer,
dev
),
reactCompilerExclude,
}
Expand All @@ -90,11 +90,13 @@ const getReactCompilerLoader = (
reactCompilerOptions: boolean | ReactCompilerOptions | undefined,
cwd: string,
isServer: boolean,
reactCompilerExclude: ((excludePath: string) => boolean) | undefined
reactCompilerExclude: ((excludePath: string) => boolean) | undefined,
isDev: boolean
) => {
const reactCompilerPlugins = getReactCompilerPlugins(
reactCompilerOptions,
isServer
isServer,
isDev
)
if (!reactCompilerPlugins) {
return undefined
Expand Down
3 changes: 2 additions & 1 deletion packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,8 @@ export default async function getBaseWebpackConfig(
config.experimental?.reactCompiler,
dir,
isNodeOrEdgeCompilation,
codeCondition.exclude
codeCondition.exclude,
dev
)

let swcTraceProfilingInitialized = false
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/config-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export interface StyledComponentsConfig {
cssProp?: boolean
}

type JSONValue =
export type JSONValue =
| string
| number
| boolean
Expand Down
Loading