88 withScope ,
99} from '@sentry/browser' ;
1010import { Event } from '@sentry/types' ;
11- import { parseSemver } from '@sentry/utils' ;
11+ import { logger , parseSemver } from '@sentry/utils' ;
1212import hoistNonReactStatics from 'hoist-non-react-statics' ;
1313import * as React from 'react' ;
1414
@@ -21,7 +21,7 @@ export type FallbackRender = (errorData: {
2121 componentStack : string | null ;
2222 eventId : string | null ;
2323 resetError ( ) : void ;
24- } ) => React . ReactNode ;
24+ } ) => React . ReactElement ;
2525
2626export type ErrorBoundaryProps = {
2727 /** If a Sentry report dialog should be rendered on error */
@@ -39,7 +39,7 @@ export type ErrorBoundaryProps = {
3939 * the error, the component stack, and an function that resets the error boundary on error.
4040 *
4141 */
42- fallback ?: React . ReactNode | FallbackRender ;
42+ fallback ?: React . ReactElement | FallbackRender ;
4343 /** Called with the error boundary encounters an error */
4444 onError ?( error : Error , componentStack : string , eventId : string ) : void ;
4545 /** Called on componentDidMount() */
@@ -160,14 +160,22 @@ class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundarySta
160160 const { error, componentStack, eventId } = this . state ;
161161
162162 if ( error ) {
163- if ( React . isValidElement ( fallback ) ) {
164- return fallback ;
165- }
163+ let element : React . ReactElement | undefined = undefined ;
166164 if ( typeof fallback === 'function' ) {
167- return fallback ( { error, componentStack, resetError : this . resetErrorBoundary , eventId } ) as FallbackRender ;
165+ element = fallback ( { error, componentStack, resetError : this . resetErrorBoundary , eventId } ) ;
166+ } else {
167+ element = fallback ;
168+ }
169+
170+ if ( React . isValidElement ( element ) ) {
171+ return element ;
172+ }
173+
174+ if ( fallback ) {
175+ logger . warn ( 'fallback did not produce a valid ReactElement' ) ;
168176 }
169177
170- // Fail gracefully if no fallback provided
178+ // Fail gracefully if no fallback provided or is not valid
171179 return null ;
172180 }
173181
0 commit comments