Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 11 commits into from
Aug 22, 2023
5 changes: 4 additions & 1 deletion packages/next/src/client/components/app-router-announcer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/server/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ const configSchema = {
},
reactStrictMode: {
type: 'boolean',
nullable: true,
},
redirects: {
isFunction: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/config-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ export const defaultConfig: NextConfig = {
serverRuntimeConfig: {},
publicRuntimeConfig: {},
reactProductionProfiling: false,
reactStrictMode: false,
reactStrictMode: null,
httpAgentOptions: {
keepAlive: true,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Root({ children }) {
return (
<html>
<body>{children}</body>
</html>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use client'
import { useEffect } from 'react'

let i = 1
export default function Page() {
useEffect(() => {
console.log(`logged ${i++} times`)
}, [])
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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`)
})
})
}
)