@@ -8,6 +8,7 @@ export type FallbackRender = (fallback: {
8
8
error : Error | null ;
9
9
componentStack : string | null ;
10
10
resetError ( ) : void ;
11
+ eventId : string | null ;
11
12
} ) => React . ReactNode ;
12
13
13
14
export type ErrorBoundaryProps = {
@@ -30,23 +31,25 @@ export type ErrorBoundaryProps = {
30
31
fallback ?: React . ReactNode | FallbackRender ;
31
32
// tslint:enable no-null-undefined-union
32
33
/** Called with the error boundary encounters an error */
33
- onError ?( error : Error , componentStack : string ) : void ;
34
+ onError ?( error : Error , componentStack : string , eventId : string ) : void ;
34
35
/** Called on componentDidMount() */
35
36
onMount ?( ) : void ;
36
37
/** Called if resetError() is called from the fallback render props function */
37
- onReset ?( error : Error | null , componentStack : string | null ) : void ;
38
+ onReset ?( error : Error | null , componentStack : string | null , eventId : string | null ) : void ;
38
39
/** Called on componentWillUnmount() */
39
- onUnmount ?( error : Error | null , componentStack : string | null ) : void ;
40
+ onUnmount ?( error : Error | null , componentStack : string | null , eventId : string | null ) : void ;
40
41
} ;
41
42
42
43
type ErrorBoundaryState = {
43
44
componentStack : string | null ;
44
45
error : Error | null ;
46
+ eventId : string | null ;
45
47
} ;
46
48
47
49
const INITIAL_STATE = {
48
50
componentStack : null ,
49
51
error : null ,
52
+ eventId : null ,
50
53
} ;
51
54
52
55
/**
@@ -60,15 +63,15 @@ class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundarySta
60
63
const eventId = Sentry . captureException ( error , { contexts : { react : { componentStack } } } ) ;
61
64
const { onError, showDialog, dialogOptions } = this . props ;
62
65
if ( onError ) {
63
- onError ( error , componentStack ) ;
66
+ onError ( error , componentStack , eventId ) ;
64
67
}
65
68
if ( showDialog ) {
66
69
Sentry . showReportDialog ( { ...dialogOptions , eventId } ) ;
67
70
}
68
71
69
72
// componentDidCatch is used over getDerivedStateFromError
70
73
// so that componentStack is accessible through state.
71
- this . setState ( { error, componentStack } ) ;
74
+ this . setState ( { error, componentStack, eventId } ) ;
72
75
}
73
76
74
77
public componentDidMount ( ) : void {
@@ -79,31 +82,32 @@ class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundarySta
79
82
}
80
83
81
84
public componentWillUnmount ( ) : void {
82
- const { error, componentStack } = this . state ;
85
+ const { error, componentStack, eventId } = this . state ;
83
86
const { onUnmount } = this . props ;
84
87
if ( onUnmount ) {
85
- onUnmount ( error , componentStack ) ;
88
+ onUnmount ( error , componentStack , eventId ) ;
86
89
}
87
90
}
88
91
89
92
public resetErrorBoundary = ( ) => {
90
93
const { onReset } = this . props ;
94
+ const { error, componentStack, eventId } = this . state ;
91
95
if ( onReset ) {
92
- onReset ( this . state . error , this . state . componentStack ) ;
96
+ onReset ( error , componentStack , eventId ) ;
93
97
}
94
98
this . setState ( INITIAL_STATE ) ;
95
99
} ;
96
100
97
101
public render ( ) : React . ReactNode {
98
102
const { fallback } = this . props ;
99
- const { error, componentStack } = this . state ;
103
+ const { error, componentStack, eventId } = this . state ;
100
104
101
105
if ( error ) {
102
106
if ( React . isValidElement ( fallback ) ) {
103
107
return fallback ;
104
108
}
105
109
if ( typeof fallback === 'function' ) {
106
- return fallback ( { error, componentStack, resetError : this . resetErrorBoundary } ) as FallbackRender ;
110
+ return fallback ( { error, componentStack, resetError : this . resetErrorBoundary , eventId } ) as FallbackRender ;
107
111
}
108
112
109
113
// Fail gracefully if no fallback provided
0 commit comments