@@ -12,6 +12,7 @@ import { getPrettyURL } from '../utils/getPrettyURL';
12
12
import { darkGray } from '../styles' ;
13
13
14
14
import type { StackFrame as StackFrameType } from '../utils/stack-frame' ;
15
+ import type { ErrorLocation } from '../utils/parseCompileError' ;
15
16
16
17
const linkStyle = {
17
18
fontSize : '0.9em' ,
@@ -45,10 +46,10 @@ const toggleStyle = {
45
46
46
47
type Props = { |
47
48
frame : StackFrameType ,
48
- launchEditorEndpoint : ?string ,
49
49
contextSize : number ,
50
50
critical : boolean ,
51
51
showCode : boolean ,
52
+ editorHandler : ( errorLoc : ErrorLocation ) => void ,
52
53
| } ;
53
54
54
55
type State = { |
@@ -66,47 +67,35 @@ class StackFrame extends Component<Props, State> {
66
67
} ) ) ;
67
68
} ;
68
69
69
- getEndpointUrl ( ) : string | null {
70
- if ( ! this . props . launchEditorEndpoint ) {
71
- return null ;
72
- }
73
- const { _originalFileName : sourceFileName } = this . props . frame ;
70
+ getErrorLocation ( ) : ErrorLocation | null {
71
+ const {
72
+ _originalFileName : fileName ,
73
+ _originalLineNumber : lineNumber ,
74
+ } = this . props . frame ;
74
75
// Unknown file
75
- if ( ! sourceFileName ) {
76
+ if ( ! fileName ) {
76
77
return null ;
77
78
}
78
79
// e.g. "/path-to-my-app/webpack/bootstrap eaddeb46b67d75e4dfc1"
79
- const isInternalWebpackBootstrapCode =
80
- sourceFileName . trim ( ) . indexOf ( ' ' ) !== - 1 ;
80
+ const isInternalWebpackBootstrapCode = fileName . trim ( ) . indexOf ( ' ' ) !== - 1 ;
81
81
if ( isInternalWebpackBootstrapCode ) {
82
82
return null ;
83
83
}
84
84
// Code is in a real file
85
- return this . props . launchEditorEndpoint || null ;
85
+ return { fileName , lineNumber : lineNumber || 1 } ;
86
86
}
87
87
88
- openInEditor = ( ) => {
89
- const endpointUrl = this . getEndpointUrl ( ) ;
90
- if ( endpointUrl === null ) {
88
+ editorHandler = ( ) => {
89
+ const errorLoc = this . getErrorLocation ( ) ;
90
+ if ( ! errorLoc ) {
91
91
return ;
92
92
}
93
-
94
- const {
95
- _originalFileName : sourceFileName ,
96
- _originalLineNumber : sourceLineNumber ,
97
- } = this . props . frame ;
98
- // Keep this in sync with react-error-overlay/middleware.js
99
- fetch (
100
- `${ endpointUrl } ?fileName=` +
101
- window . encodeURIComponent ( sourceFileName ) +
102
- '&lineNumber=' +
103
- window . encodeURIComponent ( sourceLineNumber || 1 )
104
- ) . then ( ( ) => { } , ( ) => { } ) ;
93
+ this . props . editorHandler ( errorLoc ) ;
105
94
} ;
106
95
107
96
onKeyDown = ( e : SyntheticKeyboardEvent < > ) => {
108
97
if ( e . key === 'Enter' ) {
109
- this . openInEditor ( ) ;
98
+ this . editorHandler ( ) ;
110
99
}
111
100
} ;
112
101
@@ -166,14 +155,15 @@ class StackFrame extends Component<Props, State> {
166
155
}
167
156
}
168
157
169
- const canOpenInEditor = this . getEndpointUrl ( ) !== null ;
158
+ const canOpenInEditor =
159
+ this . getErrorLocation ( ) !== null && this . props . editorHandler !== null ;
170
160
return (
171
161
< div >
172
162
< div > { functionName } </ div >
173
163
< div style = { linkStyle } >
174
164
< a
175
165
style = { canOpenInEditor ? anchorStyle : null }
176
- onClick = { canOpenInEditor ? this . openInEditor : null }
166
+ onClick = { canOpenInEditor ? this . editorHandler : null }
177
167
onKeyDown = { canOpenInEditor ? this . onKeyDown : null }
178
168
tabIndex = { canOpenInEditor ? '0' : null }
179
169
>
@@ -183,7 +173,7 @@ class StackFrame extends Component<Props, State> {
183
173
{ codeBlockProps && (
184
174
< span >
185
175
< a
186
- onClick = { canOpenInEditor ? this . openInEditor : null }
176
+ onClick = { canOpenInEditor ? this . editorHandler : null }
187
177
style = { canOpenInEditor ? codeAnchorStyle : null }
188
178
>
189
179
< CodeBlock { ...codeBlockProps } />
0 commit comments