DevTools: Add break-on-warn feature (#19048)

This commit adds a new tab to the Settings modal: Debugging

This new tab has the append component stacks feature and a new one: break on warn

This new feature adds a debugger statement into the console override
This commit is contained in:
Brian Vaughn
2020-05-29 14:34:43 -07:00
committed by GitHub
parent 89edb0eae3
commit 2efe63d99c
19 changed files with 280 additions and 78 deletions
+10 -2
View File
@@ -174,6 +174,11 @@ export function installHook(target: any): DevToolsHook | null {
// Don't patch in test environments because we don't want to interfere with Jest's own console overrides.
if (process.env.NODE_ENV !== 'test') {
try {
const appendComponentStack =
window.__REACT_DEVTOOLS_APPEND_COMPONENT_STACK__ !== false;
const breakOnConsoleErrors =
window.__REACT_DEVTOOLS_BREAK_ON_CONSOLE_ERRORS__ === true;
// The installHook() function is injected by being stringified in the browser,
// so imports outside of this function do not get included.
//
@@ -181,9 +186,12 @@ export function installHook(target: any): DevToolsHook | null {
// but Webpack wraps imports with an object (e.g. _backend_console__WEBPACK_IMPORTED_MODULE_0__)
// and the object itself will be undefined as well for the reasons mentioned above,
// so we use try/catch instead.
if (window.__REACT_DEVTOOLS_APPEND_COMPONENT_STACK__ !== false) {
if (appendComponentStack || breakOnConsoleErrors) {
registerRendererWithConsole(renderer);
patchConsole();
patchConsole({
appendComponentStack,
breakOnConsoleErrors,
});
}
} catch (error) {}
}