Skip to content

Commit fcb7dcf

Browse files
authored
Put console.stack() behind a react vendor prefix (#2164)
Matches what we did in facebook/react#9679
1 parent 71e0960 commit fcb7dcf

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

packages/react-error-overlay/src/effects/proxyConsole.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,31 @@
33
type ReactFrame = {
44
fileName: string | null,
55
lineNumber: number | null,
6-
functionName: string | null,
6+
name: string | null,
77
};
88
const reactFrameStack: Array<ReactFrame[]> = [];
99

1010
export type { ReactFrame };
1111

12+
// This is a stripped down barebones version of this proposal:
13+
// https://gist.github.com/sebmarkbage/bdefa100f19345229d526d0fdd22830f
14+
// We're implementing just enough to get the invalid element type warnings
15+
// to display the component stack in React 15.6+:
16+
// https://github.com/facebook/react/pull/9679
17+
/// TODO: a more comprehensive implementation.
18+
1219
const registerReactStack = () => {
1320
// $FlowFixMe
14-
console.stack = frames => reactFrameStack.push(frames);
21+
console.reactStack = frames => reactFrameStack.push(frames);
1522
// $FlowFixMe
16-
console.stackEnd = frames => reactFrameStack.pop();
23+
console.reactStackEnd = frames => reactFrameStack.pop();
1724
};
1825

1926
const unregisterReactStack = () => {
2027
// $FlowFixMe
21-
console.stack = undefined;
28+
console.reactStack = undefined;
2229
// $FlowFixMe
23-
console.stackEnd = undefined;
30+
console.reactStackEnd = undefined;
2431
};
2532

2633
type ConsoleProxyCallback = (message: string, frames: ReactFrame[]) => void;

packages/react-error-overlay/src/utils/warnings.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ function massage(
3333
lastFilename = fileName;
3434
lastLineNumber = lineNumber;
3535

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

4141
return { message, stack };

0 commit comments

Comments
 (0)