Skip to content

Commit 529a17b

Browse files
committed
don't mock console unless double renderering
1 parent 162bb8c commit 529a17b

17 files changed

+504
-403
lines changed

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

Lines changed: 200 additions & 137 deletions
Large diffs are not rendered by default.

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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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 as patchConsoleForStrictMode,
63+
unpatchForStrictMode as unpatchConsoleForStrictMode,
6264
} from './console';
6365
import {
6466
CONCURRENT_MODE_NUMBER,
@@ -4249,6 +4251,7 @@ export function attach(
42494251
handlePostCommitFiberRoot,
42504252
inspectElement,
42514253
logElementToConsole,
4254+
patchConsoleForStrictMode,
42524255
prepareViewAttributeSource,
42534256
prepareViewElementSource,
42544257
overrideError,
@@ -4261,6 +4264,7 @@ export function attach(
42614264
startProfiling,
42624265
stopProfiling,
42634266
storeAsGlobal,
4267+
unpatchConsoleForStrictMode,
42644268
updateComponentFilters,
42654269
};
42664270
}

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

Lines changed: 5 additions & 2 deletions
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
};
@@ -408,5 +408,8 @@ export type DevToolsHook = {
408408
// Added in v16.9 to support Fast Refresh
409409
didError?: boolean,
410410
) => void,
411+
412+
// Testing
413+
dangerous_setTargetConsoleForTesting?: (fakeConsole: Object) => void,
411414
...
412415
};

0 commit comments

Comments
 (0)