@@ -9,16 +9,21 @@ export type ErrorBoundaryProps = {
99 showDialog ?: boolean ;
1010 dialogOptions ?: Sentry . ReportDialogOptions ;
1111 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 ;
1318 onError ?( error : Error , componentStack : string ) : void ;
1419 onMount ?( ) : void ;
1520 onReset ?( error : Error | null , componentStack : string | null ) : void ;
1621 onUnmount ?( error : Error | null , componentStack : string | null ) : void ;
1722} ;
1823
1924type ErrorBoundaryState = {
20- error : Error | null ;
2125 componentStack : string | null ;
26+ error : Error | null ;
2227} ;
2328
2429const INITIAL_STATE = {
@@ -51,6 +56,17 @@ class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundarySta
5156 }
5257 }
5358
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+
5470 public componentWillUnmount ( ) : void {
5571 const { error, componentStack } = this . state ;
5672 const { onUnmount } = this . props ;
@@ -73,7 +89,7 @@ class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundarySta
7389
7490 if ( error ) {
7591 if ( typeof fallbackRender === 'function' ) {
76- return fallbackRender ( error , componentStack , this . resetErrorBoundary ) ;
92+ return fallbackRender ( { error, componentStack, resetError : this . resetErrorBoundary } ) ;
7793 }
7894 if ( React . isValidElement ( fallback ) ) {
7995 return fallback ;
0 commit comments