-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated react-error-overlay to latest Flow (0.54.0) #3065
Changes from 5 commits
6deaffb
ef9e90f
15129c9
a784af7
a910670
fc7c742
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ import CodeBlock from './StackFrameCodeBlock'; | |
import { getPrettyURL } from '../utils/getPrettyURL'; | ||
import { darkGray } from '../styles'; | ||
|
||
import type { StackFrame as StackFrameType } from '../utils/stack-frame'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here (and below). |
||
|
||
const linkStyle = { | ||
fontSize: '0.9em', | ||
marginBottom: '0.9em', | ||
|
@@ -43,7 +45,19 @@ const toggleStyle = { | |
lineHeight: '1.5', | ||
}; | ||
|
||
class StackFrame extends Component { | ||
type Props = {| | ||
frame: StackFrameType, | ||
launchEditorEndpoint: ?string, | ||
contextSize: number, | ||
critical: boolean, | ||
showCode: boolean, | ||
|}; | ||
|
||
type State = {| | ||
compiled: boolean, | ||
|}; | ||
|
||
class StackFrame extends Component<Props, State> { | ||
state = { | ||
compiled: false, | ||
}; | ||
|
@@ -54,43 +68,45 @@ class StackFrame extends Component { | |
})); | ||
}; | ||
|
||
canOpenInEditor() { | ||
getEndpointUrl() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please let's explicitly type this as |
||
if (!this.props.launchEditorEndpoint) { | ||
return; | ||
return null; | ||
} | ||
const { _originalFileName: sourceFileName } = this.props.frame; | ||
// Unknown file | ||
if (!sourceFileName) { | ||
return false; | ||
return null; | ||
} | ||
// e.g. "/path-to-my-app/webpack/bootstrap eaddeb46b67d75e4dfc1" | ||
const isInternalWebpackBootstrapCode = | ||
sourceFileName.trim().indexOf(' ') !== -1; | ||
if (isInternalWebpackBootstrapCode) { | ||
return false; | ||
return null; | ||
} | ||
// Code is in a real file | ||
return true; | ||
return this.props.launchEditorEndpoint; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why making the distinction between null and undefined? |
||
} | ||
|
||
openInEditor = () => { | ||
if (!this.canOpenInEditor()) { | ||
const endpointUrl = this.getEndpointUrl(); | ||
if (endpointUrl == null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then we can use strict |
||
return; | ||
} | ||
|
||
const { | ||
_originalFileName: sourceFileName, | ||
_originalLineNumber: sourceLineNumber, | ||
} = this.props.frame; | ||
// Keep this in sync with react-error-overlay/middleware.js | ||
fetch( | ||
`${this.props.launchEditorEndpoint}?fileName=` + | ||
`${endpointUrl}?fileName=` + | ||
window.encodeURIComponent(sourceFileName) + | ||
'&lineNumber=' + | ||
window.encodeURIComponent(sourceLineNumber || 1) | ||
).then(() => {}, () => {}); | ||
}; | ||
|
||
onKeyDown = (e: SyntheticKeyboardEvent) => { | ||
onKeyDown = (e: SyntheticKeyboardEvent<>) => { | ||
if (e.key === 'Enter') { | ||
this.openInEditor(); | ||
} | ||
|
@@ -152,12 +168,10 @@ class StackFrame extends Component { | |
} | ||
} | ||
|
||
const canOpenInEditor = this.canOpenInEditor(); | ||
const canOpenInEditor = this.getEndpointUrl() != null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here. |
||
return ( | ||
<div> | ||
<div> | ||
{functionName} | ||
</div> | ||
<div>{functionName}</div> | ||
<div style={linkStyle}> | ||
<a | ||
style={canOpenInEditor ? anchorStyle : null} | ||
|
@@ -168,7 +182,7 @@ class StackFrame extends Component { | |
{url} | ||
</a> | ||
</div> | ||
{codeBlockProps && | ||
{codeBlockProps && ( | ||
<span> | ||
<a | ||
onClick={canOpenInEditor ? this.openInEditor : null} | ||
|
@@ -179,7 +193,8 @@ class StackFrame extends Component { | |
<button style={toggleStyle} onClick={this.toggleCompiled}> | ||
{'View ' + (compiled ? 'source' : 'compiled')} | ||
</button> | ||
</span>} | ||
</span> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please always add newline before
import type
s?