Skip to content

Commit

Permalink
Don't let a DevTools or React internal error interfere with logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Aug 2, 2019
1 parent abbaedd commit 9727f4e
Showing 1 changed file with 36 additions and 32 deletions.
68 changes: 36 additions & 32 deletions src/backend/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,40 +83,44 @@ export function patch(): void {
targetConsole[method]);

const overrideMethod = (...args) => {
// 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.
const alreadyHasComponentStack =
args.length > 0 && FRAME_REGEX.exec(args[args.length - 1]);

if (!alreadyHasComponentStack) {
// If there's a component stack for at least one of the injected renderers, append it.
// We don't handle the edge case of stacks for more than one (e.g. interleaved renderers?)
for (let {
getCurrentFiber,
getDisplayNameForFiber,
} of injectedRenderers.values()) {
let current: ?Fiber = getCurrentFiber();
let ownerStack: string = '';
while (current != null) {
const name = getDisplayNameForFiber(current);
const owner = current._debugOwner;
const ownerName =
owner != null ? getDisplayNameForFiber(owner) : null;

ownerStack += describeComponentFrame(
name,
current._debugSource,
ownerName
);

current = owner;
}

if (ownerStack !== '') {
args.push(ownerStack);
break;
try {
// 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.
const alreadyHasComponentStack =
args.length > 0 && FRAME_REGEX.exec(args[args.length - 1]);

if (!alreadyHasComponentStack) {
// If there's a component stack for at least one of the injected renderers, append it.
// We don't handle the edge case of stacks for more than one (e.g. interleaved renderers?)
for (let {
getCurrentFiber,
getDisplayNameForFiber,
} of injectedRenderers.values()) {
let current: ?Fiber = getCurrentFiber();
let ownerStack: string = '';
while (current != null) {
const name = getDisplayNameForFiber(current);
const owner = current._debugOwner;
const ownerName =
owner != null ? getDisplayNameForFiber(owner) : null;

ownerStack += describeComponentFrame(
name,
current._debugSource,
ownerName
);

current = owner;
}

if (ownerStack !== '') {
args.push(ownerStack);
break;
}
}
}
} catch (error) {
// Don't let a DevTools or React internal error interfere with logging.
}

originalMethod(...args);
Expand Down

0 comments on commit 9727f4e

Please sign in to comment.