Skip to content

Commit 7c610f0

Browse files
authored
[docs] Use reactStrictMode over custom switch (#20522)
1 parent aa7bd7a commit 7c610f0

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

docs/next.config.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,17 @@ const { LANGUAGES, LANGUAGES_SSR } = require('./src/modules/constants');
88
const workspaceRoot = path.join(__dirname, '../');
99

1010
/**
11-
* @type {'legacy' | 'sync' | 'concurrent'}
11+
* https://github.com/zeit/next.js/blob/287961ed9142a53f8e9a23bafb2f31257339ea98/packages/next/next-server/server/config.ts#L10
12+
* @typedef {'legacy' | 'blocking' | 'concurrent'} ReactRenderMode
13+
* legacy - ReactDOM.render(<App />)
14+
* legacy-strict - ReactDOM.render(<React.StrictMode><App /></React.StrictMode>, Element)
15+
* blocking - ReactDOM.createSyncRoot(Element).render(<App />)
16+
* concurrent - ReactDOM.createRoot(Element).render(<App />)
17+
* @type {ReactRenderMode | 'legacy-strict'}
1218
*/
1319
const reactMode = 'legacy';
20+
// eslint-disable-next-line no-console
21+
console.log(`Using React '${reactMode}' mode.`);
1422

1523
module.exports = {
1624
typescript: {
@@ -45,10 +53,6 @@ module.exports = {
4553
config.resolve.alias['react-dom$'] = 'react-dom/profiling';
4654
config.resolve.alias['scheduler/tracing'] = 'scheduler/tracing-profiling';
4755

48-
if (reactMode !== 'legacy') {
49-
config.resolve.alias['react-transition-group'] = '@material-ui/react-transition-group';
50-
}
51-
5256
// next includes node_modules in webpack externals. Some of those have dependencies
5357
// on the aliases defined above. If a module is an external those aliases won't be used.
5458
// We need tell webpack to not consider those packages as externals.
@@ -179,5 +183,7 @@ module.exports = {
179183
{ source: '/api/:rest*', destination: '/api-docs/:rest*' },
180184
];
181185
},
186+
reactMode: reactMode.startsWith('legacy') ? 'legacy' : reactMode,
182187
},
188+
reactStrictMode: reactMode === 'legacy-strict',
183189
};

docs/pages/_app.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,6 @@ async function registerServiceWorker() {
198198
}
199199
}
200200

201-
// Add the strict mode back once the number of warnings is manageable.
202-
// We might miss important warnings by keeping the strict mode 🌊🌊🌊.
203-
const ReactMode =
204-
{
205-
// createSyncRoot compatible
206-
sync: React.StrictMode,
207-
// partial createRoot, ConcurrentMode is deprecated
208-
concurrent: React.unstable_ConcurrentMode,
209-
}[process.env.REACT_MODE] || React.Fragment;
210-
211201
let dependenciesLoaded = false;
212202

213203
function loadDependencies() {
@@ -302,7 +292,7 @@ function AppWrapper(props) {
302292
}
303293

304294
return (
305-
<ReactMode>
295+
<React.Fragment>
306296
<NextHead>
307297
{fonts.map((font) => (
308298
<link rel="stylesheet" href={font} key={font} />
@@ -318,7 +308,7 @@ function AppWrapper(props) {
318308
<LanguageNegotiation />
319309
</ReduxProvider>
320310
<GoogleAnalytics key={router.route} />
321-
</ReactMode>
311+
</React.Fragment>
322312
);
323313
}
324314

0 commit comments

Comments
 (0)