Skip to content

Commit 9c66364

Browse files
committed
don't patch console during first render
1 parent 96814e7 commit 9c66364

18 files changed

+494
-377
lines changed

packages/react-devtools-shared/src/backend/console.js

+200-137
Large diffs are not rendered by default.

packages/react-devtools-shared/src/backend/legacy/renderer.js

+6
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,10 @@ export function attach(
10731073
// Not implemented
10741074
}
10751075

1076+
function patchConsoleForStrictMode() {}
1077+
1078+
function unpatchConsoleForStrictMode() {}
1079+
10761080
return {
10771081
clearErrorsAndWarnings,
10781082
clearErrorsForFiberID,
@@ -1101,6 +1105,7 @@ export function attach(
11011105
overrideSuspense,
11021106
overrideValueAtPath,
11031107
renamePath,
1108+
patchConsoleForStrictMode,
11041109
prepareViewAttributeSource,
11051110
prepareViewElementSource,
11061111
renderer,
@@ -1109,6 +1114,7 @@ export function attach(
11091114
startProfiling,
11101115
stopProfiling,
11111116
storeAsGlobal,
1117+
unpatchConsoleForStrictMode,
11121118
updateComponentFilters,
11131119
};
11141120
}

packages/react-devtools-shared/src/backend/renderer.js

+12
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ import {inspectHooksOfFiber} from 'react-debug-tools';
5959
import {
6060
patch as patchConsole,
6161
registerRenderer as registerRendererWithConsole,
62+
patchForStrictMode,
63+
unpatchForStrictMode,
6264
} from './console';
6365
import {
6466
CONCURRENT_MODE_NUMBER,
@@ -753,6 +755,14 @@ export function attach(
753755
});
754756
}
755757

758+
function patchConsoleForStrictMode() {
759+
patchForStrictMode();
760+
}
761+
762+
function unpatchConsoleForStrictMode() {
763+
unpatchForStrictMode();
764+
}
765+
756766
const debug = (
757767
name: string,
758768
fiber: Fiber,
@@ -4242,6 +4252,7 @@ export function attach(
42424252
handlePostCommitFiberRoot,
42434253
inspectElement,
42444254
logElementToConsole,
4255+
patchConsoleForStrictMode,
42454256
prepareViewAttributeSource,
42464257
prepareViewElementSource,
42474258
overrideError,
@@ -4254,6 +4265,7 @@ export function attach(
42544265
startProfiling,
42554266
stopProfiling,
42564267
storeAsGlobal,
4268+
unpatchConsoleForStrictMode,
42574269
updateComponentFilters,
42584270
};
42594271
}

packages/react-devtools-shared/src/backend/types.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ export type ReactRenderer = {
136136
// Only injected by React v16.9+ in DEV mode.
137137
// Enables DevTools to append owners-only component stack to error messages.
138138
getCurrentFiber?: () => Fiber | null,
139-
140-
getIsStrictMode?: () => boolean,
141139
// 17.0.2+
142140
reconcilerVersion?: string,
143141
// Uniquely identifies React DOM v15.
@@ -352,6 +350,7 @@ export type RendererInterface = {
352350
path: Array<string | number>,
353351
value: any,
354352
) => void,
353+
patchConsoleForStrictMode: () => void,
355354
prepareViewAttributeSource: (
356355
id: number,
357356
path: Array<string | number>,
@@ -374,6 +373,7 @@ export type RendererInterface = {
374373
path: Array<string | number>,
375374
count: number,
376375
) => void,
376+
unpatchConsoleForStrictMode: () => void,
377377
updateComponentFilters: (componentFilters: Array<ComponentFilter>) => void,
378378
...
379379
};

0 commit comments

Comments
 (0)