@@ -8,6 +8,7 @@ export type FallbackRender = (fallback: {
88 error : Error | null ;
99 componentStack : string | null ;
1010 resetError ( ) : void ;
11+ eventId : string | null ;
1112} ) => React . ReactNode ;
1213
1314export type ErrorBoundaryProps = {
@@ -30,23 +31,25 @@ export type ErrorBoundaryProps = {
3031 fallback ?: React . ReactNode | FallbackRender ;
3132 // tslint:enable no-null-undefined-union
3233 /** Called with the error boundary encounters an error */
33- onError ?( error : Error , componentStack : string ) : void ;
34+ onError ?( error : Error , componentStack : string , eventId : string ) : void ;
3435 /** Called on componentDidMount() */
3536 onMount ?( ) : void ;
3637 /** 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 ;
3839 /** Called on componentWillUnmount() */
39- onUnmount ?( error : Error | null , componentStack : string | null ) : void ;
40+ onUnmount ?( error : Error | null , componentStack : string | null , eventId : string | null ) : void ;
4041} ;
4142
4243type ErrorBoundaryState = {
4344 componentStack : string | null ;
4445 error : Error | null ;
46+ eventId : string | null ;
4547} ;
4648
4749const INITIAL_STATE = {
4850 componentStack : null ,
4951 error : null ,
52+ eventId : null ,
5053} ;
5154
5255/**
@@ -60,15 +63,15 @@ class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundarySta
6063 const eventId = Sentry . captureException ( error , { contexts : { react : { componentStack } } } ) ;
6164 const { onError, showDialog, dialogOptions } = this . props ;
6265 if ( onError ) {
63- onError ( error , componentStack ) ;
66+ onError ( error , componentStack , eventId ) ;
6467 }
6568 if ( showDialog ) {
6669 Sentry . showReportDialog ( { ...dialogOptions , eventId } ) ;
6770 }
6871
6972 // componentDidCatch is used over getDerivedStateFromError
7073 // so that componentStack is accessible through state.
71- this . setState ( { error, componentStack } ) ;
74+ this . setState ( { error, componentStack, eventId } ) ;
7275 }
7376
7477 public componentDidMount ( ) : void {
@@ -79,31 +82,32 @@ class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundarySta
7982 }
8083
8184 public componentWillUnmount ( ) : void {
82- const { error, componentStack } = this . state ;
85+ const { error, componentStack, eventId } = this . state ;
8386 const { onUnmount } = this . props ;
8487 if ( onUnmount ) {
85- onUnmount ( error , componentStack ) ;
88+ onUnmount ( error , componentStack , eventId ) ;
8689 }
8790 }
8891
8992 public resetErrorBoundary = ( ) => {
9093 const { onReset } = this . props ;
94+ const { error, componentStack, eventId } = this . state ;
9195 if ( onReset ) {
92- onReset ( this . state . error , this . state . componentStack ) ;
96+ onReset ( error , componentStack , eventId ) ;
9397 }
9498 this . setState ( INITIAL_STATE ) ;
9599 } ;
96100
97101 public render ( ) : React . ReactNode {
98102 const { fallback } = this . props ;
99- const { error, componentStack } = this . state ;
103+ const { error, componentStack, eventId } = this . state ;
100104
101105 if ( error ) {
102106 if ( React . isValidElement ( fallback ) ) {
103107 return fallback ;
104108 }
105109 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 ;
107111 }
108112
109113 // Fail gracefully if no fallback provided
0 commit comments