File tree Expand file tree Collapse file tree 3 files changed +55
-5
lines changed
packages/react-devtools-shared/src/devtools/views/ErrorBoundary Expand file tree Collapse file tree 3 files changed +55
-5
lines changed Original file line number Diff line number Diff line change @@ -21,13 +21,15 @@ type Props = {|
2121
2222type State = { |
2323 callStack : string | null ,
24+ canDismiss : boolean ,
2425 componentStack : string | null ,
2526 errorMessage : string | null ,
2627 hasError : boolean ,
2728| } ;
2829
2930const InitialState : State = {
3031 callStack : null ,
32+ canDismiss : false ,
3133 componentStack : null ,
3234 errorMessage : null ,
3335 hasError : false ,
@@ -77,13 +79,20 @@ export default class ErrorBoundary extends Component<Props, State> {
7779
7880 render ( ) {
7981 const { children} = this . props ;
80- const { callStack, componentStack, errorMessage, hasError} = this . state ;
82+ const {
83+ callStack,
84+ canDismiss,
85+ componentStack,
86+ errorMessage,
87+ hasError,
88+ } = this . state ;
8189
8290 if ( hasError ) {
8391 return (
8492 < ErrorView
8593 callStack = { callStack }
8694 componentStack = { componentStack }
95+ dismissError = { canDismiss ? this . _dismissError : null }
8796 errorMessage = { errorMessage } >
8897 < Suspense fallback = { < SearchingGitHubIssues /> } >
8998 < SuspendingErrorView
@@ -99,9 +108,16 @@ export default class ErrorBoundary extends Component<Props, State> {
99108 return children ;
100109 }
101110
111+ _dismissError = ( ) = > {
112+ this . setState ( InitialState ) ;
113+ } ;
114+
102115 _onStoreError = ( error : Error ) = > {
103116 if ( ! this . state . hasError ) {
104- this . setState ( ErrorBoundary . getDerivedStateFromError ( error ) ) ;
117+ this . setState ( {
118+ ...ErrorBoundary . getDerivedStateFromError ( error ) ,
119+ canDismiss : true ,
120+ } ) ;
105121 }
106122 } ;
107123}
Original file line number Diff line number Diff line change 88 */
99
1010import * as React from 'react' ;
11+ import Button from '../Button' ;
12+ import ButtonIcon from '../ButtonIcon' ;
1113import styles from './shared.css' ;
1214
1315type Props = { |
1416 callStack : string | null ,
1517 children : React$Node ,
1618 componentStack : string | null ,
19+ dismissError : Function | null ,
1720 errorMessage : string | null ,
1821| } ;
1922
2023export default function ErrorView ( {
2124 callStack,
2225 children,
2326 componentStack,
27+ dismissError = null ,
2428 errorMessage,
2529} : Props ) {
2630 return (
2731 < div className = { styles . ErrorBoundary } >
2832 { children }
2933 < div className = { styles . ErrorInfo } >
30- < div className = { styles . Header } >
31- Uncaught Error: { errorMessage || '' }
34+ < div className = { styles . HeaderRow } >
35+ < div className = { styles . Header } >
36+ Uncaught Error: { errorMessage || '' }
37+ </ div >
38+ { dismissError !== null && (
39+ < Button className = { styles . CloseButton } onClick = { dismissError } >
40+ Dismiss
41+ < ButtonIcon className = { styles . CloseButtonIcon } type = "close" />
42+ </ Button >
43+ ) }
3244 </ div >
3345 { ! ! callStack && (
3446 < div className = { styles . Stack } >
Original file line number Diff line number Diff line change 3737 overflow : auto;
3838}
3939
40- .Header {
40+ .HeaderRow {
41+ display : flex;
42+ flex-direction : row;
4143 font-size : var (--font-size-sans-large );
4244 font-weight : bold;
4345 color : var (--color-error-text );
4446}
4547
48+ .Header {
49+ flex : 1 1 auto;
50+ overflow : hidden;
51+ text-overflow : ellipsis;
52+ white-space : nowrap;
53+ min-width : 0 ;
54+ }
55+
4656.Stack {
4757 margin-top : 0.5rem ;
4858 white-space : pre-wrap;
7585.ReproSteps {
7686 margin-left : 0.25rem ;
7787 color : var (--color-console-warning-text );
88+ overflow : hidden;
89+ text-overflow : ellipsis;
90+ white-space : nowrap;
91+ min-width : 0 ;
7892}
7993
8094.UpdateExistingIssuePrompt {
8195 margin-right : 0.25rem ;
8296 color : var (--color-console-warning-text );
97+ }
98+
99+ .CloseButton {
100+ font-weight : bold;
101+ }
102+
103+ .CloseButtonIcon {
104+ margin-left : 0.25rem ;
83105}
You can’t perform that action at this time.
0 commit comments