Skip to content

Commit ce7ce9c

Browse files
Brian Vaughnkoto
authored andcommitted
DevTools: Patch console methods even when only show-inline-warnings/errors enabled (facebook#20688)
1 parent bd2b8cb commit ce7ce9c

File tree

4 files changed

+66
-3
lines changed

4 files changed

+66
-3
lines changed

packages/react-devtools-shared/src/__tests__/console-test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ describe('console', () => {
4747
patchConsole({
4848
appendComponentStack: true,
4949
breakOnWarn: false,
50+
showInlineWarningsAndErrors: false,
5051
});
5152

5253
const inject = global.__REACT_DEVTOOLS_GLOBAL_HOOK__.inject;
@@ -79,12 +80,61 @@ describe('console', () => {
7980
expect(fakeConsole.warn).not.toBe(mockWarn);
8081
});
8182

83+
it('should patch the console when appendComponentStack is enabled', () => {
84+
unpatchConsole();
85+
86+
expect(fakeConsole.error).toBe(mockError);
87+
expect(fakeConsole.warn).toBe(mockWarn);
88+
89+
patchConsole({
90+
appendComponentStack: true,
91+
breakOnWarn: false,
92+
showInlineWarningsAndErrors: false,
93+
});
94+
95+
expect(fakeConsole.error).not.toBe(mockError);
96+
expect(fakeConsole.warn).not.toBe(mockWarn);
97+
});
98+
99+
it('should patch the console when breakOnWarn is enabled', () => {
100+
unpatchConsole();
101+
102+
expect(fakeConsole.error).toBe(mockError);
103+
expect(fakeConsole.warn).toBe(mockWarn);
104+
105+
patchConsole({
106+
appendComponentStack: false,
107+
breakOnWarn: true,
108+
showInlineWarningsAndErrors: false,
109+
});
110+
111+
expect(fakeConsole.error).not.toBe(mockError);
112+
expect(fakeConsole.warn).not.toBe(mockWarn);
113+
});
114+
115+
it('should patch the console when showInlineWarningsAndErrors is enabled', () => {
116+
unpatchConsole();
117+
118+
expect(fakeConsole.error).toBe(mockError);
119+
expect(fakeConsole.warn).toBe(mockWarn);
120+
121+
patchConsole({
122+
appendComponentStack: false,
123+
breakOnWarn: false,
124+
showInlineWarningsAndErrors: true,
125+
});
126+
127+
expect(fakeConsole.error).not.toBe(mockError);
128+
expect(fakeConsole.warn).not.toBe(mockWarn);
129+
});
130+
82131
it('should only patch the console once', () => {
83132
const {error, warn} = fakeConsole;
84133

85134
patchConsole({
86135
appendComponentStack: true,
87136
breakOnWarn: false,
137+
showInlineWarningsAndErrors: false,
88138
});
89139

90140
expect(fakeConsole.error).toBe(error);
@@ -339,6 +389,7 @@ describe('console', () => {
339389
patchConsole({
340390
appendComponentStack: true,
341391
breakOnWarn: false,
392+
showInlineWarningsAndErrors: false,
342393
});
343394
act(() => ReactDOM.render(<Child />, document.createElement('div')));
344395

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,11 @@ export default class Agent extends EventEmitter<{|
622622
// or in the case of React Native- if the backend is just finding out the preference-
623623
// then install or uninstall the console overrides.
624624
// It's safe to call these methods multiple times, so we don't need to worry about that.
625-
if (appendComponentStack || breakOnConsoleErrors) {
625+
if (
626+
appendComponentStack ||
627+
breakOnConsoleErrors ||
628+
showInlineWarningsAndErrors
629+
) {
626630
patchConsole({
627631
appendComponentStack,
628632
breakOnConsoleErrors,

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,11 @@ export function attach(
645645
window.__REACT_DEVTOOLS_BREAK_ON_CONSOLE_ERRORS__ === true;
646646
const showInlineWarningsAndErrors =
647647
window.__REACT_DEVTOOLS_SHOW_INLINE_WARNINGS_AND_ERRORS__ !== false;
648-
if (appendComponentStack || breakOnConsoleErrors) {
648+
if (
649+
appendComponentStack ||
650+
breakOnConsoleErrors ||
651+
showInlineWarningsAndErrors
652+
) {
649653
patchConsole({
650654
appendComponentStack,
651655
breakOnConsoleErrors,

packages/react-devtools-shared/src/hook.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,11 @@ export function installHook(target: any): DevToolsHook | null {
192192
// but Webpack wraps imports with an object (e.g. _backend_console__WEBPACK_IMPORTED_MODULE_0__)
193193
// and the object itself will be undefined as well for the reasons mentioned above,
194194
// so we use try/catch instead.
195-
if (appendComponentStack || breakOnConsoleErrors) {
195+
if (
196+
appendComponentStack ||
197+
breakOnConsoleErrors ||
198+
showInlineWarningsAndErrors
199+
) {
196200
registerRendererWithConsole(renderer);
197201
patchConsole({
198202
appendComponentStack,

0 commit comments

Comments
 (0)