Skip to content

Commit

Permalink
Add StrictMode toggle (#9161)
Browse files Browse the repository at this point in the history
* Add StrictMode toggle

* Rename option to reactStrictMode

* Default to false initially
  • Loading branch information
devknoll authored and timneutkens committed Oct 25, 2019
1 parent be42300 commit 4421448
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +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.reactStrictMode
),
...(isServer
? {
// Fix bad-actors in the npm ecosystem (e.g. `node-formidable`)
Expand Down
14 changes: 11 additions & 3 deletions packages/next/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
<AppContainer>
<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
)

Expand Down
1 change: 1 addition & 0 deletions packages/next/next-server/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const defaultConfig: { [key: string]: any } = {
},
serverRuntimeConfig: {},
publicRuntimeConfig: {},
reactStrictMode: false,
}

const experimentalWarning = execOnce(() => {
Expand Down

0 comments on commit 4421448

Please sign in to comment.