@@ -40,7 +40,7 @@ export const ErrorBoundary = ({
4040 children ?: React . ReactNode ;
4141} ) => {
4242 const parentContext = React . useContext ( ErrorContext ) ;
43- const [ error , setThisError ] = React . useState < SentryError | null > ( null ) ;
43+ const [ error , setThisError ] = React . useState < ( SentryError & { isInline ?: boolean } ) | null > ( null ) ;
4444 const errorFallbacks : { [ _ : string ] : JSX . Element } = React . useMemo ( ( ) => ( {
4545 ...( includeDefaultHandlers ? defaultErrorFallbacks : { } ) ,
4646 ...props . errorFallbacks
@@ -91,11 +91,14 @@ export const ErrorBoundary = ({
9191 }
9292 } , [ props . userUuid ] ) ;
9393
94- const setError = React . useCallback ( ( input : unknown , componentStack ?: string ) => {
94+ const setError = React . useCallback ( ( input : unknown , componentStack ?: string , isInline ?: boolean ) => {
9595
9696 if ( input === null ) {
9797 setThisError ( null ) ;
98- parentContext . setError ( null ) ;
98+
99+ if ( parentContext . initialized ) {
100+ parentContext . setError ( null ) ;
101+ }
99102 return ;
100103 }
101104
@@ -104,7 +107,7 @@ export const ErrorBoundary = ({
104107
105108 if ( type in errorFallbacks || ! parentContext . initialized ) {
106109 setThisError ( {
107- error, type, componentStack,
110+ error, type, componentStack, isInline ,
108111 eventId : Sentry . captureException ( error , {
109112 level : errorLevels [ type ] ?? 'error'
110113 } )
@@ -120,18 +123,20 @@ export const ErrorBoundary = ({
120123 initialized : true
121124 } ) , [ error , setError ] ) ;
122125
126+ const errorDisplay = typedFallback || defaultErrorFallbacks . generic ;
127+
123128 // ErrorBoundary is not an actual ErrorBoundary becuase writing class components
124129 // is too annoying, we delegate just the catching part to RenderErrorCatcher
125130 return < ErrorContext . Provider value = { contextValue } >
126- { error
127- ? ( typedFallback || defaultErrorFallbacks . generic )
128- : < RenderErrorCatcher catch = { setError } > { children } </ RenderErrorCatcher >
131+ { error && error . isInline
132+ ? errorDisplay
133+ : < RenderErrorCatcher catch = { setError } > { error ? errorDisplay : children } </ RenderErrorCatcher >
129134 }
130135 </ ErrorContext . Provider > ;
131136} ;
132137
133138type RenderErrorCatcherProps = {
134- catch : ( error : unknown , componentStack : string ) => void ;
139+ catch : ( error : unknown , componentStack : string , isInline : boolean ) => void ;
135140 children ?: React . ReactNode ;
136141} ;
137142// according to https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary
@@ -147,7 +152,7 @@ class RenderErrorCatcher extends React.Component<RenderErrorCatcherProps, { hasE
147152 }
148153
149154 componentDidCatch ( error : unknown , info : React . ErrorInfo ) {
150- this . props . catch ( error , info . componentStack ) ;
155+ this . props . catch ( error , info . componentStack , true ) ;
151156 }
152157
153158 render ( ) {
0 commit comments