-
-
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 3 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 |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
|
||
/* @flow */ | ||
import React, { Component } from 'react'; | ||
import type { Node } from 'react'; | ||
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 everywhere below). |
||
import { black } from '../styles'; | ||
|
||
const overlayStyle = { | ||
|
@@ -31,10 +32,19 @@ const overlayStyle = { | |
color: black, | ||
}; | ||
|
||
class ErrorOverlay extends Component { | ||
type Props = {| | ||
children: Node, | ||
shortcutHandler?: (eventKey: string) => void, | ||
|}; | ||
|
||
type State = {| | ||
collapsed: boolean, | ||
|}; | ||
|
||
class ErrorOverlay extends Component<Props, State> { | ||
iframeWindow: window = null; | ||
|
||
getIframeWindow = (element: HTMLDivElement) => { | ||
getIframeWindow = (element: ?HTMLDivElement) => { | ||
if (element) { | ||
const document = element.ownerDocument; | ||
this.iframeWindow = document.defaultView; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,4 +65,5 @@ function RuntimeError({ errorRecord, launchEditorEndpoint }: Props) { | |
); | ||
} | ||
|
||
export type { ErrorRecord }; | ||
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. Can you please just 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. 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. Or you probably meant:
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. Yes, that's what I meant. |
||
export default RuntimeError; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,19 @@ import CloseButton from '../components/CloseButton'; | |
import NavigationBar from '../components/NavigationBar'; | ||
import RuntimeError from './RuntimeError'; | ||
import Footer from '../components/Footer'; | ||
import type { ErrorRecord } from './RuntimeError'; | ||
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. Could you please always add newline before import x from 'x';
import y from 'y';
import type { z } from 'z';
// code |
||
|
||
class RuntimeErrorContainer extends PureComponent { | ||
type Props = {| | ||
errorRecords: ErrorRecord[], | ||
close: () => void, | ||
launchEditorEndpoint: ?string, | ||
|}; | ||
|
||
type State = {| | ||
currentIndex: number, | ||
|}; | ||
|
||
class RuntimeErrorContainer extends PureComponent<Props, State> { | ||
state = { | ||
currentIndex: 0, | ||
}; | ||
|
@@ -54,13 +65,14 @@ class RuntimeErrorContainer extends PureComponent { | |
return ( | ||
<ErrorOverlay shortcutHandler={this.shortcutHandler}> | ||
<CloseButton close={close} /> | ||
{totalErrors > 1 && | ||
{totalErrors > 1 && ( | ||
<NavigationBar | ||
currentError={this.state.currentIndex + 1} | ||
totalErrors={totalErrors} | ||
previous={this.previous} | ||
next={this.next} | ||
/>} | ||
/> | ||
)} | ||
<RuntimeError | ||
errorRecord={errorRecords[this.state.currentIndex]} | ||
launchEditorEndpoint={this.props.launchEditorEndpoint} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ import React, { Component } from 'react'; | |
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', | ||
|
@@ -43,7 +44,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, | ||
}; | ||
|
@@ -74,7 +87,7 @@ class StackFrame extends Component { | |
} | ||
|
||
openInEditor = () => { | ||
if (!this.canOpenInEditor()) { | ||
if (!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. Why did this change? Seems like it's more permissive than it used to be. 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. 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. Sorry I have no idea how to fix this other than adding the same condition twice.
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. You can replace 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. 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. 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. It's not working because you're not using the return value and instead read the same thing again from props. Flow doesn't know the props are immutable so it's bailing out thinking they might have changed. I am suggesting to use the return value of 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. 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. You are calling the function twice. Flow can’t know that the value hasn’t changed since last call. You need to do this: const endpointUrl = this.getEndpointUrl();
if (endpointUrl === null) {
return;
}
// ...
// By now Flow knows endpointUrl can't possibly be null
fetch(
`${endpointUrl}/...`
) 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. Thank you, now I understand. |
||
return; | ||
} | ||
const { | ||
|
@@ -90,7 +103,7 @@ class StackFrame extends Component { | |
).then(() => {}, () => {}); | ||
}; | ||
|
||
onKeyDown = (e: SyntheticKeyboardEvent) => { | ||
onKeyDown = (e: SyntheticKeyboardEvent<>) => { | ||
if (e.key === 'Enter') { | ||
this.openInEditor(); | ||
} | ||
|
@@ -155,9 +168,7 @@ class StackFrame extends Component { | |
const canOpenInEditor = this.canOpenInEditor(); | ||
return ( | ||
<div> | ||
<div> | ||
{functionName} | ||
</div> | ||
<div>{functionName}</div> | ||
<div style={linkStyle}> | ||
<a | ||
style={canOpenInEditor ? anchorStyle : null} | ||
|
@@ -168,7 +179,7 @@ class StackFrame extends Component { | |
{url} | ||
</a> | ||
</div> | ||
{codeBlockProps && | ||
{codeBlockProps && ( | ||
<span> | ||
<a | ||
onClick={canOpenInEditor ? this.openInEditor : null} | ||
|
@@ -179,7 +190,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.
Can you please leave them typed as
React.Element
instead ofimport type
? For explicitness (Element
is a global in Flow that means DOM element).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.
Without the import flow fails:
Flow doc suggests to import React as a namespace with import * as React from 'react' instead of as a default with import React from 'react'.
https://flow.org/en/docs/react/components/
But I thought it was a big change and I decided not to do it.
Cheers
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.
I could use this syntax: React$Element.
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.
Oh, I guess you'd have to
import * as React from 'react'
at which point you'd bump into a false positive warning about accessingPropTypes
in 15. Let's keep it this way then.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.
Can you do
import type { Element as ReactElement } from 'react'
?