File tree 3 files changed +23
-6
lines changed
packages/react-error-overlay/src
3 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -127,8 +127,8 @@ function createFrame(
127
127
lastElement : boolean
128
128
) {
129
129
const { compiled } = frameSetting ;
130
+ let { functionName } = frame ;
130
131
const {
131
- functionName,
132
132
fileName,
133
133
lineNumber,
134
134
columnNumber,
@@ -139,6 +139,14 @@ function createFrame(
139
139
_originalScriptCode : sourceLines ,
140
140
} = frame ;
141
141
142
+ // TODO: find a better place for this.
143
+ // Chrome has a bug with inferring function.name:
144
+ // https://github.com/facebookincubator/create-react-app/issues/2097
145
+ // Let's ignore a meaningless name we get for top-level modules.
146
+ if ( functionName === 'Object.friendlySyntaxErrorLabel' ) {
147
+ functionName = '(anonymous function)' ;
148
+ }
149
+
142
150
let url ;
143
151
if ( ! compiled && sourceFileName && sourceLineNumber ) {
144
152
url = sourceFileName + ':' + sourceLineNumber ;
Original file line number Diff line number Diff line change @@ -50,11 +50,19 @@ function createOverlay(
50
50
// Create header
51
51
const header = document . createElement ( 'div' ) ;
52
52
applyStyles ( header , headerStyle ) ;
53
- if ( message . match ( / ^ \w * : / ) ) {
54
- header . appendChild ( document . createTextNode ( message ) ) ;
55
- } else {
56
- header . appendChild ( document . createTextNode ( name + ': ' + message ) ) ;
57
- }
53
+
54
+ // Make message prettier
55
+ let finalMessage = message . match ( / ^ \w * : / ) ? name + ': ' + message : message ;
56
+ finalMessage = finalMessage
57
+ // TODO: maybe remove this prefix from fbjs?
58
+ // It's just scaring people
59
+ . replace ( 'Invariant Violation: ' , '' )
60
+ // Break the actionable part to the next line.
61
+ // AFAIK React 16+ should already do this.
62
+ . replace ( ' Check the render method' , '\n\nCheck the render method' ) ;
63
+
64
+ // Put it in the DOM
65
+ header . appendChild ( document . createTextNode ( finalMessage ) ) ;
58
66
container . appendChild ( header ) ;
59
67
60
68
// Create trace
Original file line number Diff line number Diff line change @@ -65,6 +65,7 @@ const headerStyle = {
65
65
'font-size' : '1.7em' ,
66
66
'font-weight' : 'bold' ,
67
67
color : red ,
68
+ 'white-space' : 'pre-wrap' ,
68
69
} ;
69
70
70
71
const functionNameStyle = {
You can’t perform that action at this time.
0 commit comments