Skip to content

Commit

Permalink
Enable strict mode by default for app dir
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens committed Oct 27, 2022
1 parent 11a6fd7 commit a58ba30
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 11 additions & 1 deletion packages/next/build/webpack-config.ts
Expand Up @@ -244,7 +244,17 @@ export function getDefineEnv({
'process.env.__NEXT_BUILD_INDICATOR_POSITION': JSON.stringify(
config.devIndicators.buildActivityPosition
),
'process.env.__NEXT_STRICT_MODE': JSON.stringify(config.reactStrictMode),
'process.env.__NEXT_STRICT_MODE': JSON.stringify(
config.reactStrictMode === null ? false : config.reactStrictMode
),
'process.env.__NEXT_STRICT_MODE_APP': JSON.stringify(
// When next.config.js does not have reactStrictMode enabling appDir will enable it.
config.reactStrictMode === null
? config.experimental.appDir
? true
: false
: config.reactStrictMode
),
'process.env.__NEXT_REACT_ROOT': JSON.stringify(hasReactRoot),
'process.env.__NEXT_OPTIMIZE_FONTS': JSON.stringify(
!dev && config.optimizeFonts
Expand Down
2 changes: 1 addition & 1 deletion packages/next/client/app-index.tsx
Expand Up @@ -149,7 +149,7 @@ function ServerRoot({ cacheKey }: { cacheKey: string }): JSX.Element {
return root
}

const StrictModeIfEnabled = process.env.__NEXT_STRICT_MODE
const StrictModeIfEnabled = process.env.__NEXT_STRICT_MODE_APP
? React.StrictMode
: React.Fragment

Expand Down
4 changes: 2 additions & 2 deletions packages/next/server/config-shared.ts
Expand Up @@ -391,7 +391,7 @@ export interface NextConfig extends Record<string, any> {
*
* @see [React Strict Mode](https://nextjs.org/docs/api-reference/next.config.js/react-strict-mode)
*/
reactStrictMode?: boolean
reactStrictMode?: boolean | null

/**
* Add public (in browser) runtime configuration to your app
Expand Down Expand Up @@ -545,7 +545,7 @@ export const defaultConfig: NextConfig = {
excludeDefaultMomentLocales: true,
serverRuntimeConfig: {},
publicRuntimeConfig: {},
reactStrictMode: false,
reactStrictMode: null,
httpAgentOptions: {
keepAlive: true,
},
Expand Down

0 comments on commit a58ba30

Please sign in to comment.