Skip to content

Commit

Permalink
don't patch console during first render
Browse files Browse the repository at this point in the history
  • Loading branch information
lunaruan committed Sep 13, 2021
1 parent 96814e7 commit 9fb81cd
Show file tree
Hide file tree
Showing 18 changed files with 496 additions and 394 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,
};
}
12 changes: 12 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,
unpatchForStrictMode,
} from './console';
import {
CONCURRENT_MODE_NUMBER,
Expand Down Expand Up @@ -753,6 +755,14 @@ export function attach(
});
}

function patchConsoleForStrictMode() {
patchForStrictMode();
}

function unpatchConsoleForStrictMode() {
unpatchForStrictMode();
}

const debug = (
name: string,
fiber: Fiber,
Expand Down Expand Up @@ -4242,6 +4252,7 @@ export function attach(
handlePostCommitFiberRoot,
inspectElement,
logElementToConsole,
patchConsoleForStrictMode,
prepareViewAttributeSource,
prepareViewElementSource,
overrideError,
Expand All @@ -4254,6 +4265,7 @@ export function attach(
startProfiling,
stopProfiling,
storeAsGlobal,
unpatchConsoleForStrictMode,
updateComponentFilters,
};
}
4 changes: 2 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
Loading

0 comments on commit 9fb81cd

Please sign in to comment.