File tree 3 files changed +55
-5
lines changed
packages/react-devtools-shared/src/devtools/views/ErrorBoundary 3 files changed +55
-5
lines changed Original file line number Diff line number Diff line change @@ -21,13 +21,15 @@ type Props = {|
21
21
22
22
type State = { |
23
23
callStack : string | null ,
24
+ canDismiss : boolean ,
24
25
componentStack : string | null ,
25
26
errorMessage : string | null ,
26
27
hasError : boolean ,
27
28
| } ;
28
29
29
30
const InitialState : State = {
30
31
callStack : null ,
32
+ canDismiss : false ,
31
33
componentStack : null ,
32
34
errorMessage : null ,
33
35
hasError : false ,
@@ -77,13 +79,20 @@ export default class ErrorBoundary extends Component<Props, State> {
77
79
78
80
render ( ) {
79
81
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 ;
81
89
82
90
if ( hasError ) {
83
91
return (
84
92
< ErrorView
85
93
callStack = { callStack }
86
94
componentStack = { componentStack }
95
+ dismissError = { canDismiss ? this . _dismissError : null }
87
96
errorMessage = { errorMessage } >
88
97
< Suspense fallback = { < SearchingGitHubIssues /> } >
89
98
< SuspendingErrorView
@@ -99,9 +108,16 @@ export default class ErrorBoundary extends Component<Props, State> {
99
108
return children ;
100
109
}
101
110
111
+ _dismissError = ( ) = > {
112
+ this . setState ( InitialState ) ;
113
+ } ;
114
+
102
115
_onStoreError = ( error : Error ) = > {
103
116
if ( ! this . state . hasError ) {
104
- this . setState ( ErrorBoundary . getDerivedStateFromError ( error ) ) ;
117
+ this . setState ( {
118
+ ...ErrorBoundary . getDerivedStateFromError ( error ) ,
119
+ canDismiss : true ,
120
+ } ) ;
105
121
}
106
122
} ;
107
123
}
Original file line number Diff line number Diff line change 8
8
*/
9
9
10
10
import * as React from 'react' ;
11
+ import Button from '../Button' ;
12
+ import ButtonIcon from '../ButtonIcon' ;
11
13
import styles from './shared.css' ;
12
14
13
15
type Props = { |
14
16
callStack : string | null ,
15
17
children : React$Node ,
16
18
componentStack : string | null ,
19
+ dismissError : Function | null ,
17
20
errorMessage : string | null ,
18
21
| } ;
19
22
20
23
export default function ErrorView ( {
21
24
callStack,
22
25
children,
23
26
componentStack,
27
+ dismissError = null ,
24
28
errorMessage,
25
29
} : Props ) {
26
30
return (
27
31
< div className = { styles . ErrorBoundary } >
28
32
{ children }
29
33
< 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
+ ) }
32
44
</ div >
33
45
{ ! ! callStack && (
34
46
< div className = { styles . Stack } >
Original file line number Diff line number Diff line change 37
37
overflow : auto;
38
38
}
39
39
40
- .Header {
40
+ .HeaderRow {
41
+ display : flex;
42
+ flex-direction : row;
41
43
font-size : var (--font-size-sans-large );
42
44
font-weight : bold;
43
45
color : var (--color-error-text );
44
46
}
45
47
48
+ .Header {
49
+ flex : 1 1 auto;
50
+ overflow : hidden;
51
+ text-overflow : ellipsis;
52
+ white-space : nowrap;
53
+ min-width : 0 ;
54
+ }
55
+
46
56
.Stack {
47
57
margin-top : 0.5rem ;
48
58
white-space : pre-wrap;
75
85
.ReproSteps {
76
86
margin-left : 0.25rem ;
77
87
color : var (--color-console-warning-text );
88
+ overflow : hidden;
89
+ text-overflow : ellipsis;
90
+ white-space : nowrap;
91
+ min-width : 0 ;
78
92
}
79
93
80
94
.UpdateExistingIssuePrompt {
81
95
margin-right : 0.25rem ;
82
96
color : var (--color-console-warning-text );
97
+ }
98
+
99
+ .CloseButton {
100
+ font-weight : bold;
101
+ }
102
+
103
+ .CloseButtonIcon {
104
+ margin-left : 0.25rem ;
83
105
}
You can’t perform that action at this time.
0 commit comments