Unverified Commit 96a59344 authored by Balázs Orbán's avatar Balázs Orbán Committed by GitHub

fix(app): enable React Strict Mode by default (#53375)

### What?

Let Next.js enable React Strict Mode by default for the App Router.

This caught a bug with the `AppRouterAnnouncer` added in #47018 which
should be fixed as well.

### Why?

This logic:


https://github.com/vercel/next.js/blob/a0d1d728b9003f12c9df6c5e9a33bc4c33cef0ab/packages/next/src/build/webpack-config.ts#L326-L333

assumes that the default value of `reactStrictMode` is `null`, but it
was set to `false` in #46656.

### How?

This PR reverts the default value to `null`.


Closes NEXT-1484
Fixes #53315

---------
Co-authored-by: 's avatarTim Neutkens <tim@timneutkens.nl>
parent c89f97ea
......@@ -57,7 +57,10 @@ export function AppRouterAnnouncer({ tree }: { tree: FlightRouterState }) {
// Only announce the title change, but not for the first load because screen
// readers do that automatically.
if (previousTitle.current !== undefined) {
if (
previousTitle.current !== undefined &&
previousTitle.current !== currentTitle
) {
setRouteAnnouncement(currentTitle)
}
previousTitle.current = currentTitle
......
......@@ -748,6 +748,7 @@ const configSchema = {
},
reactStrictMode: {
type: 'boolean',
nullable: true,
},
redirects: {
isFunction: true,
......
......@@ -682,7 +682,7 @@ export const defaultConfig: NextConfig = {
serverRuntimeConfig: {},
publicRuntimeConfig: {},
reactProductionProfiling: false,
reactStrictMode: false,
reactStrictMode: null,
httpAgentOptions: {
keepAlive: true,
},
......
export default function Root({ children }) {
return (
<html>
<body>{children}</body>
</html>
)
}
'use client'
import { useEffect } from 'react'
let i = 1
export default function Page() {
useEffect(() => {
console.log(`logged ${i++} times`)
}, [])
}
import { createNextDescribe } from 'e2e-utils'
import { BrowserInterface } from 'test/lib/browsers/base'
createNextDescribe(
'Strict Mode enabled by default',
{
files: __dirname,
},
({ next }) => {
// Recommended for tests that need a full browser
it('should work using browser', async () => {
const browser: BrowserInterface = await next.browser('/')
const logs = await browser.log()
const userLogs = logs.filter(
(log) => log.source === 'log' && log.message.match(/logged \d times/)
)
expect(userLogs.length).toBe(2)
userLogs.forEach((log, i) => {
expect(log.message).toBe(`logged ${i + 1} times`)
})
})
}
)
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