Commit fcb7dcf1 authored by Dan Abramov's avatar Dan Abramov Committed by GitHub
Browse files

Put console.stack() behind a react vendor prefix (#2164)

Matches what we did in https://github.com/facebook/react/pull/9679
parent 71e09604
3 merge requests!12191Lim.Pisey.168:/Identified - We are currently investigating reports of missing build logs. The issue has been identified and a resolution is in progress. We will provide a further update when available.Mar 21, 09:02 UTC,!12853brikk,!5717Automatically extract project file structure from build bundle file
Showing with 15 additions and 8 deletions
+15 -8
...@@ -3,24 +3,31 @@ ...@@ -3,24 +3,31 @@
type ReactFrame = { type ReactFrame = {
fileName: string | null, fileName: string | null,
lineNumber: number | null, lineNumber: number | null,
functionName: string | null, name: string | null,
}; };
const reactFrameStack: Array<ReactFrame[]> = []; const reactFrameStack: Array<ReactFrame[]> = [];
export type { 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 = () => { const registerReactStack = () => {
// $FlowFixMe // $FlowFixMe
console.stack = frames => reactFrameStack.push(frames); console.reactStack = frames => reactFrameStack.push(frames);
// $FlowFixMe // $FlowFixMe
console.stackEnd = frames => reactFrameStack.pop(); console.reactStackEnd = frames => reactFrameStack.pop();
}; };
const unregisterReactStack = () => { const unregisterReactStack = () => {
// $FlowFixMe // $FlowFixMe
console.stack = undefined; console.reactStack = undefined;
// $FlowFixMe // $FlowFixMe
console.stackEnd = undefined; console.reactStackEnd = undefined;
}; };
type ConsoleProxyCallback = (message: string, frames: ReactFrame[]) => void; type ConsoleProxyCallback = (message: string, frames: ReactFrame[]) => void;
......
...@@ -33,9 +33,9 @@ function massage( ...@@ -33,9 +33,9 @@ function massage(
lastFilename = fileName; lastFilename = fileName;
lastLineNumber = lineNumber; lastLineNumber = lineNumber;
let { functionName } = frames[index]; let { name } = frames[index];
functionName = functionName || '(anonymous function)'; name = name || '(anonymous function)';
stack += `in ${functionName} (at ${fileName}:${lineNumber})\n`; stack += `in ${name} (at ${fileName}:${lineNumber})\n`;
} }
return { message, stack }; return { message, stack };
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment