-
-
Couldn't load subscription status.
- Fork 27.1k
Convert react-error-overlay to React #2515
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
Changes from 4 commits
1e43349
822a5f6
f8eb25d
c68882c
03c74c6
36f1361
6521757
898b639
f51d851
f7ce856
313943d
92f1d76
448b16f
216efc7
645dc42
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 |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| [ignore] | ||
| .*/node_modules/eslint-plugin-jsx-a11y/.* | ||
|
|
||
| [include] | ||
| src/**/*.js | ||
|
|
||
| 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) { | ||
|
||
| mount(() => render(error)); | ||
| } else { | ||
| render(error); | ||
| } | ||
| return unmount; | ||
| } | ||
|
|
||
| export { showCompileErrorOverlay }; | ||
| 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; |
| 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; |
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
webpackHotDevClientto 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-utilsandreact-dev-utils.