Commit 4421448f authored by Gerald Monaco's avatar Gerald Monaco Committed by Tim Neutkens

Add `StrictMode` toggle (#9161)

* Add StrictMode toggle

* Rename option to reactStrictMode

* Default to false initially
parent be42300e
...@@ -736,6 +736,9 @@ export default async function getBaseWebpackConfig( ...@@ -736,6 +736,9 @@ export default async function getBaseWebpackConfig(
'process.env.__NEXT_PRERENDER_INDICATOR': JSON.stringify( 'process.env.__NEXT_PRERENDER_INDICATOR': JSON.stringify(
config.devIndicators.autoPrerender config.devIndicators.autoPrerender
), ),
'process.env.__NEXT_STRICT_MODE': JSON.stringify(
config.reactStrictMode
),
...(isServer ...(isServer
? { ? {
// Fix bad-actors in the npm ecosystem (e.g. `node-formidable`) // Fix bad-actors in the npm ecosystem (e.g. `node-formidable`)
......
...@@ -372,11 +372,19 @@ async function doRender ({ App, Component, props, err }) { ...@@ -372,11 +372,19 @@ async function doRender ({ App, Component, props, err }) {
appProps appProps
}) })
// We catch runtime errors using componentDidCatch which will trigger renderError const elem = (
renderReactElement(
<AppContainer> <AppContainer>
<App {...appProps} /> <App {...appProps} />
</AppContainer>, </AppContainer>
)
// We catch runtime errors using componentDidCatch which will trigger renderError
renderReactElement(
process.env.__NEXT_STRICT_MODE ? (
<React.StrictMode>{elem}</React.StrictMode>
) : (
elem
),
appElement appElement
) )
......
...@@ -53,6 +53,7 @@ const defaultConfig: { [key: string]: any } = { ...@@ -53,6 +53,7 @@ const defaultConfig: { [key: string]: any } = {
}, },
serverRuntimeConfig: {}, serverRuntimeConfig: {},
publicRuntimeConfig: {}, publicRuntimeConfig: {},
reactStrictMode: false,
} }
const experimentalWarning = execOnce(() => { const experimentalWarning = execOnce(() => {
......
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