-
-
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
Convert react-error-overlay to React #2515
Merged
Merged
Changes from 4 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1e43349
Convert react-error-overlay to React
tharakawj 822a5f6
Update compile-time error overlay to use react-error-overlay components
tharakawj f8eb25d
Run Prettier
gaearon c68882c
Merge with master
gaearon 03c74c6
Port the fix from #3012
gaearon 36f1361
Move the function name fix into StackFrame itself
gaearon 6521757
Fix clicking on source code snippet to open the code in editor
tharakawj 898b639
Use exact objects + minor style tweak
gaearon f51d851
Don't linkify frames that don't exist on the disk
gaearon f7ce856
Fix lint
gaearon 313943d
Consolidate iframe rendering logic
gaearon 92f1d76
Remove circular dependency between react-dev-utils and react-error-ov…
gaearon 448b16f
Fix lint
gaearon 216efc7
Fix decoupling of react-dev-utils and react-error-overlay by moving m…
gaearon 645dc42
Deduplicate identical errors
gaearon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
[ignore] | ||
.*/node_modules/eslint-plugin-jsx-a11y/.* | ||
|
||
[include] | ||
src/**/*.js | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
/* @flow */ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import CompileErrorContainer from './containers/CompileErrorContainer'; | ||
import { mountOverlayIframe } from './utils/dom/mountOverlayIframe'; | ||
|
||
let container: HTMLDivElement | null = null; | ||
let iframeReference: HTMLIFrameElement | null = null; | ||
|
||
function mount(callback) { | ||
iframeReference = mountOverlayIframe(containerDiv => { | ||
container = containerDiv; | ||
callback(); | ||
}); | ||
} | ||
|
||
function unmount() { | ||
if (iframeReference === null) { | ||
return; | ||
} | ||
ReactDOM.unmountComponentAtNode(container); | ||
window.document.body.removeChild(iframeReference); | ||
iframeReference = null; | ||
container = null; | ||
} | ||
|
||
function render(error: string) { | ||
ReactDOM.render(<CompileErrorContainer error={error} />, container); | ||
} | ||
|
||
function showCompileErrorOverlay(error: string) { | ||
if (container == 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. Shouldn't we check |
||
mount(() => render(error)); | ||
} else { | ||
render(error); | ||
} | ||
return unmount; | ||
} | ||
|
||
export { showCompileErrorOverlay }; |
38 changes: 38 additions & 0 deletions
38
packages/react-error-overlay/src/components/CloseButton.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
/* @flow */ | ||
import React from 'react'; | ||
import { black } from '../styles'; | ||
|
||
const closeButtonStyle = { | ||
color: black, | ||
lineHeight: '1rem', | ||
fontSize: '1.5rem', | ||
padding: '1rem', | ||
cursor: 'pointer', | ||
position: 'absolute', | ||
right: 0, | ||
top: 0, | ||
}; | ||
|
||
type CloseCallback = () => void; | ||
function CloseButton({ close }: { close: CloseCallback }) { | ||
return ( | ||
<span | ||
title="Click or press Escape to dismiss." | ||
onClick={close} | ||
style={closeButtonStyle} | ||
> | ||
× | ||
</span> | ||
); | ||
} | ||
|
||
export default CloseButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
/* @flow */ | ||
import React from 'react'; | ||
import { redTransparent, yellowTransparent } from '../styles'; | ||
|
||
const _preStyle = { | ||
display: 'block', | ||
padding: '0.5em', | ||
marginTop: '0.5em', | ||
marginBottom: '0.5em', | ||
overflowX: 'auto', | ||
whiteSpace: 'pre-wrap', | ||
borderRadius: '0.25rem', | ||
}; | ||
|
||
const primaryPreStyle = { | ||
..._preStyle, | ||
backgroundColor: redTransparent, | ||
}; | ||
|
||
const secondaryPreStyle = { | ||
..._preStyle, | ||
backgroundColor: yellowTransparent, | ||
}; | ||
|
||
const codeStyle = { | ||
fontFamily: 'Consolas, Menlo, monospace', | ||
}; | ||
|
||
type CodeBlockPropsType = { | ||
main: boolean, | ||
codeHTML: string, | ||
}; | ||
|
||
function CodeBlock(props: CodeBlockPropsType) { | ||
const preStyle = props.main ? primaryPreStyle : secondaryPreStyle; | ||
const codeBlock = { __html: props.codeHTML }; | ||
|
||
return ( | ||
<pre style={preStyle}> | ||
<code style={codeStyle} dangerouslySetInnerHTML={codeBlock} /> | ||
</pre> | ||
); | ||
} | ||
|
||
export default CodeBlock; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This technically means that we're forcing every user of
webpackHotDevClient
to use our runtime overlay (since the module sets up the hooks on execution). I'm not quite sure if I want this or not. Maybe it's okay, but then there's no need in the separate entry point in the webpack config. Or maybe we should keep them working independently in which case this could be a separately imported file.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.
Yes. I also don't think it's a good idea to tight coupling between error-overly and webpack client. But then how do we access webpack errors? with a separate SockJS connection?
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.
Also, this will remove circular dependency between
react-dev-utils
andreact-dev-utils
.