@@ -9,16 +9,21 @@ export type ErrorBoundaryProps = {
9
9
showDialog ?: boolean ;
10
10
dialogOptions ?: Sentry . ReportDialogOptions ;
11
11
fallback ?: React . ReactNode ;
12
- fallbackRender ?( error : Error | null , componentStack : string | null , resetErrorBoundary : ( ) => void ) : React . ReactNode ;
12
+ renderKey ?: string | number ;
13
+ fallbackRender ?( fallback : {
14
+ error : Error | null ;
15
+ componentStack : string | null ;
16
+ resetError ( ) : void ;
17
+ } ) : React . ReactNode ;
13
18
onError ?( error : Error , componentStack : string ) : void ;
14
19
onMount ?( ) : void ;
15
20
onReset ?( error : Error | null , componentStack : string | null ) : void ;
16
21
onUnmount ?( error : Error | null , componentStack : string | null ) : void ;
17
22
} ;
18
23
19
24
type ErrorBoundaryState = {
20
- error : Error | null ;
21
25
componentStack : string | null ;
26
+ error : Error | null ;
22
27
} ;
23
28
24
29
const INITIAL_STATE = {
@@ -51,6 +56,17 @@ class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundarySta
51
56
}
52
57
}
53
58
59
+ public componentDidUpdate ( prevProps : ErrorBoundaryProps ) : void {
60
+ const { error } = this . state ;
61
+ const { renderKey, onReset } = this . props ;
62
+ if ( error !== null && ! Object . is ( renderKey , prevProps . renderKey ) ) {
63
+ if ( onReset ) {
64
+ onReset ( this . state . error , this . state . componentStack ) ;
65
+ }
66
+ this . setState ( INITIAL_STATE ) ;
67
+ }
68
+ }
69
+
54
70
public componentWillUnmount ( ) : void {
55
71
const { error, componentStack } = this . state ;
56
72
const { onUnmount } = this . props ;
@@ -73,7 +89,7 @@ class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundarySta
73
89
74
90
if ( error ) {
75
91
if ( typeof fallbackRender === 'function' ) {
76
- return fallbackRender ( error , componentStack , this . resetErrorBoundary ) ;
92
+ return fallbackRender ( { error, componentStack, resetError : this . resetErrorBoundary } ) ;
77
93
}
78
94
if ( React . isValidElement ( fallback ) ) {
79
95
return fallback ;
0 commit comments