From 50393dc3a0c59cfefd349d31992256efd6f8c261 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Tue, 22 Dec 2020 10:58:47 -0800 Subject: [PATCH] React Native fixes for new inline errors feature (#20502) --- .../src/__tests__/inspectedElementContext-test.js | 3 ++- .../react-devtools-shared/src/backend/console.js | 13 +++++-------- .../react-devtools-shared/src/backend/renderer.js | 2 +- packages/react-devtools-shared/src/hook.js | 2 +- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/react-devtools-shared/src/__tests__/inspectedElementContext-test.js b/packages/react-devtools-shared/src/__tests__/inspectedElementContext-test.js index 153bb43801ba2..c60560302f55f 100644 --- a/packages/react-devtools-shared/src/__tests__/inspectedElementContext-test.js +++ b/packages/react-devtools-shared/src/__tests__/inspectedElementContext-test.js @@ -2014,7 +2014,8 @@ describe('InspectedElementContext', () => { Object { "errors": Array [ Array [ - "Warning: Each child in a list should have a unique \\"key\\" prop. See https://reactjs.org/link/warning-keys for more information.", + "Warning: Each child in a list should have a unique \\"key\\" prop. See https://reactjs.org/link/warning-keys for more information. + at Example", 1, ], ], diff --git a/packages/react-devtools-shared/src/backend/console.js b/packages/react-devtools-shared/src/backend/console.js index cc9eff11f6841..ee06d2173eabf 100644 --- a/packages/react-devtools-shared/src/backend/console.js +++ b/packages/react-devtools-shared/src/backend/console.js @@ -140,12 +140,12 @@ export function patch({ targetConsole[method]); const overrideMethod = (...args) => { - const lastArg = args.length > 0 ? args[args.length - 1] : null; - const alreadyHasComponentStack = - lastArg !== null && isStringComponentStack(lastArg); - let shouldAppendWarningStack = false; if (consoleSettingsRef.appendComponentStack) { + const lastArg = args.length > 0 ? args[args.length - 1] : null; + const alreadyHasComponentStack = + lastArg !== null && isStringComponentStack(lastArg); + // If we are ever called with a string that already has a component stack, // e.g. a React error/warning, don't append a second stack. shouldAppendWarningStack = !alreadyHasComponentStack; @@ -176,10 +176,7 @@ export function patch({ current, ((method: any): 'error' | 'warn'), // Copy args before we mutate them (e.g. adding the component stack) - alreadyHasComponentStack - ? // Replace component stack with an empty string in case there's a string placeholder for it. - [...args.slice(0, -1), ''] - : args.slice(), + args.slice(), ); } } diff --git a/packages/react-devtools-shared/src/backend/renderer.js b/packages/react-devtools-shared/src/backend/renderer.js index 11beef37f76d4..e44b58f71009e 100644 --- a/packages/react-devtools-shared/src/backend/renderer.js +++ b/packages/react-devtools-shared/src/backend/renderer.js @@ -634,7 +634,7 @@ export function attach( const breakOnConsoleErrors = window.__REACT_DEVTOOLS_BREAK_ON_CONSOLE_ERRORS__ === true; const showInlineWarningsAndErrors = - window.__REACT_DEVTOOLS_SHOW_INLINE_WARNINGS_AND_ERRORS__ === true; + window.__REACT_DEVTOOLS_SHOW_INLINE_WARNINGS_AND_ERRORS__ !== false; if (appendComponentStack || breakOnConsoleErrors) { patchConsole({ appendComponentStack, diff --git a/packages/react-devtools-shared/src/hook.js b/packages/react-devtools-shared/src/hook.js index 9bec6f40a1537..3bb2eb23115ab 100644 --- a/packages/react-devtools-shared/src/hook.js +++ b/packages/react-devtools-shared/src/hook.js @@ -183,7 +183,7 @@ export function installHook(target: any): DevToolsHook | null { const breakOnConsoleErrors = window.__REACT_DEVTOOLS_BREAK_ON_CONSOLE_ERRORS__ === true; const showInlineWarningsAndErrors = - window.__REACT_DEVTOOLS_SHOW_INLINE_WARNINGS_AND_ERRORS__ === true; + window.__REACT_DEVTOOLS_SHOW_INLINE_WARNINGS_AND_ERRORS__ !== false; // The installHook() function is injected by being stringified in the browser, // so imports outside of this function do not get included.