Skip to content

Commit

Permalink
React Native fixes for new inline errors feature (#20502)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn authored Dec 22, 2020
1 parent 09a2c36 commit 50393dc
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
],
Expand Down
13 changes: 5 additions & 8 deletions packages/react-devtools-shared/src/backend/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-devtools-shared/src/backend/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-devtools-shared/src/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 50393dc

Please sign in to comment.