@@ -36,13 +36,13 @@ export type ErrorBoundaryProps = {
36
36
*/
37
37
fallback ?: React . ReactElement | FallbackRender | undefined ;
38
38
/** Called when the error boundary encounters an error */
39
- onError ?: ( ( error : unknown , componentStack : string , eventId : string ) => void ) | undefined ;
39
+ onError ?: ( ( error : unknown , componentStack : string | undefined , eventId : string ) => void ) | undefined ;
40
40
/** Called on componentDidMount() */
41
41
onMount ?: ( ( ) => void ) | undefined ;
42
42
/** Called if resetError() is called from the fallback render props function */
43
- onReset ?: ( ( error : unknown , componentStack : string | null , eventId : string | null ) => void ) | undefined ;
43
+ onReset ?: ( ( error : unknown , componentStack : string | null | undefined , eventId : string | null ) => void ) | undefined ;
44
44
/** Called on componentWillUnmount() */
45
- onUnmount ?: ( ( error : unknown , componentStack : string | null , eventId : string | null ) => void ) | undefined ;
45
+ onUnmount ?: ( ( error : unknown , componentStack : string | null | undefined , eventId : string | null ) => void ) | undefined ;
46
46
/** Called before the error is captured by Sentry, allows for you to add tags or context using the scope */
47
47
beforeCapture ?: ( ( scope : Scope , error : unknown , componentStack : string | undefined ) => void ) | undefined ;
48
48
} ;
@@ -97,16 +97,19 @@ class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundarySta
97
97
98
98
public componentDidCatch ( error : unknown , errorInfo : React . ErrorInfo ) : void {
99
99
const { componentStack } = errorInfo ;
100
+ // TODO(v9): Remove this check and type `componentStack` to be React.ErrorInfo['componentStack'].
101
+ const passedInComponentStack : string | undefined = componentStack == null ? undefined : componentStack ;
102
+
100
103
const { beforeCapture, onError, showDialog, dialogOptions } = this . props ;
101
104
withScope ( scope => {
102
105
if ( beforeCapture ) {
103
- beforeCapture ( scope , error , componentStack ) ;
106
+ beforeCapture ( scope , error , passedInComponentStack ) ;
104
107
}
105
108
106
109
const eventId = captureReactException ( error , errorInfo , { mechanism : { handled : ! ! this . props . fallback } } ) ;
107
110
108
111
if ( onError ) {
109
- onError ( error , componentStack , eventId ) ;
112
+ onError ( error , passedInComponentStack , eventId ) ;
110
113
}
111
114
if ( showDialog ) {
112
115
this . _lastEventId = eventId ;
@@ -186,7 +189,6 @@ function withErrorBoundary<P extends Record<string, any>>(
186
189
WrappedComponent : React . ComponentType < P > ,
187
190
errorBoundaryOptions : ErrorBoundaryProps ,
188
191
) : React . FC < P > {
189
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
190
192
const componentDisplayName = WrappedComponent . displayName || WrappedComponent . name || UNKNOWN_COMPONENT ;
191
193
192
194
const Wrapped : React . FC < P > = ( props : P ) => (
@@ -195,12 +197,13 @@ function withErrorBoundary<P extends Record<string, any>>(
195
197
</ ErrorBoundary >
196
198
) ;
197
199
198
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
199
200
Wrapped . displayName = `errorBoundary(${ componentDisplayName } )` ;
200
201
201
202
// Copy over static methods from Wrapped component to Profiler HOC
202
203
// See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over
203
- hoistNonReactStatics ( Wrapped , WrappedComponent ) ;
204
+ // Need to set type to any because of hoist-non-react-statics typing
205
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
206
+ hoistNonReactStatics ( Wrapped , WrappedComponent as any ) ;
204
207
return Wrapped ;
205
208
}
206
209
0 commit comments