From eefdfc46d67ea57d9c248e2c799cced2f1390c49 Mon Sep 17 00:00:00 2001 From: Gerald Monaco Date: Wed, 9 Oct 2019 20:50:37 +0000 Subject: [PATCH 1/3] Add StrictMode toggle --- packages/next/build/webpack-config.ts | 1 + packages/next/client/index.js | 14 +++++++++++--- packages/next/next-server/server/config.ts | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index bf049ee6eac1b..fa618466df2f3 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -736,6 +736,7 @@ export default async function getBaseWebpackConfig( 'process.env.__NEXT_PRERENDER_INDICATOR': JSON.stringify( config.devIndicators.autoPrerender ), + 'process.env.__NEXT_STRICT_MODE': JSON.stringify(config.strictMode), ...(isServer ? { // Fix bad-actors in the npm ecosystem (e.g. `node-formidable`) diff --git a/packages/next/client/index.js b/packages/next/client/index.js index 2eed1010881e8..02118913c1c4e 100644 --- a/packages/next/client/index.js +++ b/packages/next/client/index.js @@ -372,11 +372,19 @@ async function doRender ({ App, Component, props, err }) { appProps }) - // We catch runtime errors using componentDidCatch which will trigger renderError - renderReactElement( + const elem = ( - , + + ) + + // We catch runtime errors using componentDidCatch which will trigger renderError + renderReactElement( + process.env.__NEXT_STRICT_MODE ? ( + {elem} + ) : ( + elem + ), appElement ) diff --git a/packages/next/next-server/server/config.ts b/packages/next/next-server/server/config.ts index 60f3ac43758eb..8e81b56a0a58d 100644 --- a/packages/next/next-server/server/config.ts +++ b/packages/next/next-server/server/config.ts @@ -53,6 +53,7 @@ const defaultConfig: { [key: string]: any } = { }, serverRuntimeConfig: {}, publicRuntimeConfig: {}, + strictMode: true, } const experimentalWarning = execOnce(() => { From 5f27e0de35044a4a8d5248111112c936d3a4daf1 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Sat, 26 Oct 2019 00:07:05 +0200 Subject: [PATCH 2/3] Rename option to reactStrictMode --- packages/next/build/webpack-config.ts | 4 +++- packages/next/next-server/server/config.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index fa618466df2f3..fd6ec5cd00d00 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -736,7 +736,9 @@ export default async function getBaseWebpackConfig( 'process.env.__NEXT_PRERENDER_INDICATOR': JSON.stringify( config.devIndicators.autoPrerender ), - 'process.env.__NEXT_STRICT_MODE': JSON.stringify(config.strictMode), + 'process.env.__NEXT_STRICT_MODE': JSON.stringify( + config.reactStrictMode + ), ...(isServer ? { // Fix bad-actors in the npm ecosystem (e.g. `node-formidable`) diff --git a/packages/next/next-server/server/config.ts b/packages/next/next-server/server/config.ts index 8e81b56a0a58d..23021ed427502 100644 --- a/packages/next/next-server/server/config.ts +++ b/packages/next/next-server/server/config.ts @@ -53,7 +53,7 @@ const defaultConfig: { [key: string]: any } = { }, serverRuntimeConfig: {}, publicRuntimeConfig: {}, - strictMode: true, + reactStrictMode: true, } const experimentalWarning = execOnce(() => { From 3ad10e806dbcbee8878c0a7a0c8c38bcbb1f2d19 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Sat, 26 Oct 2019 00:17:32 +0200 Subject: [PATCH 3/3] Default to false initially --- packages/next/next-server/server/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/next-server/server/config.ts b/packages/next/next-server/server/config.ts index 23021ed427502..712eca701718a 100644 --- a/packages/next/next-server/server/config.ts +++ b/packages/next/next-server/server/config.ts @@ -53,7 +53,7 @@ const defaultConfig: { [key: string]: any } = { }, serverRuntimeConfig: {}, publicRuntimeConfig: {}, - reactStrictMode: true, + reactStrictMode: false, } const experimentalWarning = execOnce(() => {