Skip to content

Commit

Permalink
don't mock console unless double renderering
Browse files Browse the repository at this point in the history
  • Loading branch information
lunaruan committed Sep 21, 2021
1 parent 162bb8c commit 529a17b
Show file tree
Hide file tree
Showing 17 changed files with 504 additions and 403 deletions.
337 changes: 200 additions & 137 deletions packages/react-devtools-shared/src/backend/console.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions packages/react-devtools-shared/src/backend/legacy/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,10 @@ export function attach(
// Not implemented
}

function patchConsoleForStrictMode() {}

function unpatchConsoleForStrictMode() {}

return {
clearErrorsAndWarnings,
clearErrorsForFiberID,
Expand Down Expand Up @@ -1101,6 +1105,7 @@ export function attach(
overrideSuspense,
overrideValueAtPath,
renamePath,
patchConsoleForStrictMode,
prepareViewAttributeSource,
prepareViewElementSource,
renderer,
Expand All @@ -1109,6 +1114,7 @@ export function attach(
startProfiling,
stopProfiling,
storeAsGlobal,
unpatchConsoleForStrictMode,
updateComponentFilters,
};
}
4 changes: 4 additions & 0 deletions packages/react-devtools-shared/src/backend/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ import {inspectHooksOfFiber} from 'react-debug-tools';
import {
patch as patchConsole,
registerRenderer as registerRendererWithConsole,
patchForStrictMode as patchConsoleForStrictMode,
unpatchForStrictMode as unpatchConsoleForStrictMode,
} from './console';
import {
CONCURRENT_MODE_NUMBER,
Expand Down Expand Up @@ -4249,6 +4251,7 @@ export function attach(
handlePostCommitFiberRoot,
inspectElement,
logElementToConsole,
patchConsoleForStrictMode,
prepareViewAttributeSource,
prepareViewElementSource,
overrideError,
Expand All @@ -4261,6 +4264,7 @@ export function attach(
startProfiling,
stopProfiling,
storeAsGlobal,
unpatchConsoleForStrictMode,
updateComponentFilters,
};
}
7 changes: 5 additions & 2 deletions packages/react-devtools-shared/src/backend/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ export type ReactRenderer = {
// Only injected by React v16.9+ in DEV mode.
// Enables DevTools to append owners-only component stack to error messages.
getCurrentFiber?: () => Fiber | null,

getIsStrictMode?: () => boolean,
// 17.0.2+
reconcilerVersion?: string,
// Uniquely identifies React DOM v15.
Expand Down Expand Up @@ -352,6 +350,7 @@ export type RendererInterface = {
path: Array<string | number>,
value: any,
) => void,
patchConsoleForStrictMode: () => void,
prepareViewAttributeSource: (
id: number,
path: Array<string | number>,
Expand All @@ -374,6 +373,7 @@ export type RendererInterface = {
path: Array<string | number>,
count: number,
) => void,
unpatchConsoleForStrictMode: () => void,
updateComponentFilters: (componentFilters: Array<ComponentFilter>) => void,
...
};
Expand Down Expand Up @@ -408,5 +408,8 @@ export type DevToolsHook = {
// Added in v16.9 to support Fast Refresh
didError?: boolean,
) => void,

// Testing
dangerous_setTargetConsoleForTesting?: (fakeConsole: Object) => void,
...
};
Loading

0 comments on commit 529a17b

Please sign in to comment.