Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions packages/react-error-overlay/src/effects/proxyConsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,31 @@
type ReactFrame = {
fileName: string | null,
lineNumber: number | null,
functionName: string | null,
name: string | null,
};
const reactFrameStack: Array<ReactFrame[]> = [];

export type { ReactFrame };

// This is a stripped down barebones version of this proposal:
// https://gist.github.com/sebmarkbage/bdefa100f19345229d526d0fdd22830f
// We're implementing just enough to get the invalid element type warnings
// to display the component stack in React 15.6+:
// https://github.com/facebook/react/pull/9679
/// TODO: a more comprehensive implementation.

const registerReactStack = () => {
// $FlowFixMe
console.stack = frames => reactFrameStack.push(frames);
console.reactStack = frames => reactFrameStack.push(frames);
// $FlowFixMe
console.stackEnd = frames => reactFrameStack.pop();
console.reactStackEnd = frames => reactFrameStack.pop();
};

const unregisterReactStack = () => {
// $FlowFixMe
console.stack = undefined;
console.reactStack = undefined;
// $FlowFixMe
console.stackEnd = undefined;
console.reactStackEnd = undefined;
};

type ConsoleProxyCallback = (message: string, frames: ReactFrame[]) => void;
Expand Down
6 changes: 3 additions & 3 deletions packages/react-error-overlay/src/utils/warnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ function massage(
lastFilename = fileName;
lastLineNumber = lineNumber;

let { functionName } = frames[index];
functionName = functionName || '(anonymous function)';
stack += `in ${functionName} (at ${fileName}:${lineNumber})\n`;
let { name } = frames[index];
name = name || '(anonymous function)';
stack += `in ${name} (at ${fileName}:${lineNumber})\n`;
}

return { message, stack };
Expand Down