@@ -5,6 +5,7 @@ import { formatComponentStack } from './format-component-stack';
55
66export type FlareErrorBoundaryFallbackProps = {
77 error : Error ;
8+ componentStack : string [ ] ;
89 resetErrorBoundary : ( ) => void ;
910} ;
1011
@@ -13,17 +14,18 @@ export type FlareErrorBoundaryProps = PropsWithChildren<{
1314 resetKeys ?: unknown [ ] ;
1415 beforeCapture ?: ( params : { error : Error ; errorInfo : ErrorInfo } ) => void ;
1516 onError ?: ( params : { error : Error ; errorInfo : ErrorInfo } ) => void ;
16- onReset ?: ( ) => void ;
17+ onReset ?: ( error : Error | null ) => void ;
1718} > ;
1819
1920export type FlareErrorBoundaryState = {
2021 error : Error | null ;
22+ componentStack : string [ ] ;
2123} ;
2224
2325export class FlareErrorBoundary extends Component < FlareErrorBoundaryProps , FlareErrorBoundaryState > {
24- state : FlareErrorBoundaryState = { error : null } ;
26+ state : FlareErrorBoundaryState = { error : null , componentStack : [ ] } ;
2527
26- static getDerivedStateFromError ( error : Error ) : FlareErrorBoundaryState {
28+ static getDerivedStateFromError ( error : Error ) : Partial < FlareErrorBoundaryState > {
2729 return { error } ;
2830 }
2931
@@ -39,6 +41,8 @@ export class FlareErrorBoundary extends Component<FlareErrorBoundaryProps, Flare
3941 } ,
4042 } ;
4143
44+ this . setState ( { componentStack : context . react . componentStack } ) ;
45+
4246 flare . report ( error , context , { react : { errorInfo } } ) ;
4347
4448 this . props . onError ?.( {
@@ -64,9 +68,11 @@ export class FlareErrorBoundary extends Component<FlareErrorBoundaryProps, Flare
6468 }
6569
6670 reset = ( ) => {
67- this . setState ( { error : null } ) ;
71+ const { error } = this . state ;
72+
73+ this . props . onReset ?.( error ) ;
6874
69- this . props . onReset ?. ( ) ;
75+ this . setState ( { error : null , componentStack : [ ] } ) ;
7076 } ;
7177
7278 render ( ) {
@@ -78,6 +84,7 @@ export class FlareErrorBoundary extends Component<FlareErrorBoundaryProps, Flare
7884 if ( typeof fallback === 'function' ) {
7985 return fallback ( {
8086 error,
87+ componentStack : this . state . componentStack ,
8188 resetErrorBoundary : this . reset ,
8289 } ) ;
8390 }
0 commit comments