Skip to content

Commit

Permalink
Allow disabling Strict mode in app
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens committed Oct 26, 2022
1 parent a1072c6 commit 78270ac
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/next/client/app-index.tsx
Expand Up @@ -2,7 +2,7 @@
import '../build/polyfills/polyfill-module'
// @ts-ignore react-dom/client exists when using React 18
import ReactDOMClient from 'react-dom/client'
import React, { use } from 'react'
import React, { ReactNode, use } from 'react'
import { createFromReadableStream } from 'next/dist/compiled/react-server-dom-webpack/client'

import measureWebVitals from './performance-relayer'
Expand Down Expand Up @@ -149,6 +149,14 @@ function ServerRoot({ cacheKey }: { cacheKey: string }): JSX.Element {
return root
}

function StrictModeIfEnabled({ children }: { children: React.ReactNode }) {
return process.env.__NEXT_STRICT_MODE ? (
<React.StrictMode>{children}</React.StrictMode>
) : (
<>{children}</>
)
}

function Root({ children }: React.PropsWithChildren<{}>): React.ReactElement {
React.useEffect(() => {
measureWebVitals()
Expand Down Expand Up @@ -213,7 +221,7 @@ export function hydrate() {
}

const reactEl = (
<React.StrictMode>
<StrictModeIfEnabled>
<HeadManagerContext.Provider
value={{
appDir: true,
Expand All @@ -223,7 +231,7 @@ export function hydrate() {
<RSCComponent />
</Root>
</HeadManagerContext.Provider>
</React.StrictMode>
</StrictModeIfEnabled>
)

const isError = document.documentElement.id === '__next_error__'
Expand Down

0 comments on commit 78270ac

Please sign in to comment.