@@ -38,6 +38,7 @@ export const ErrorBoundary = ({
3838 sentryInit ?: Sentry . BrowserOptions ;
3939 errorFallbacks ?: { [ _ : string ] : JSX . Element }
4040 errorLevels ?: { [ _ : string ] : Sentry . SeverityLevel }
41+ userUuid ?: string ; // Optional user UUID to set in Sentry
4142} ) => {
4243 const [ error , setError ] = React . useState < SentryError | null > ( null ) ;
4344 const errorFallbacks : { [ _ : string ] : JSX . Element } = { ...defaultErrorFallbacks , ...props . errorFallbacks } ;
@@ -48,7 +49,12 @@ export const ErrorBoundary = ({
4849 // Optionally re-render with the children so they can display inline errors with <ErrorMessage />
4950 const renderElement = error && renderFallback ? ( typedFallback || fallback ) : < > { children } </ > ;
5051
51- type WindowWithUserData = Window & { _OX_USER_DATA ?: User }
52+ type FrontendConfigType = {
53+ releaseId : string ;
54+ [ key : string ] : unknown ; // any other properties, can vary depending on the frontend config repository
55+ } ;
56+
57+ type WindowWithUserData = Window & { _OX_USER_DATA ?: User , _OX_FRONTEND_CONFIG ?: FrontendConfigType }
5258
5359 React . useEffect ( ( ) => {
5460 if ( ! sentryDsn && ! sentryInit ) {
@@ -61,6 +67,7 @@ export const ErrorBoundary = ({
6167 initCalled . current = true ;
6268 Sentry . init ( sentryInit || {
6369 dsn : sentryDsn ,
70+ release : ( window as WindowWithUserData ) . _OX_FRONTEND_CONFIG ?. releaseId ,
6471 environment : window . location . hostname ,
6572 initialScope : {
6673 user : { uuid : ( window as WindowWithUserData ) . _OX_USER_DATA ?. uuid } ,
@@ -73,6 +80,12 @@ export const ErrorBoundary = ({
7380 } ) ;
7481 } , [ sentryDsn , sentryInit ] ) ;
7582
83+ React . useEffect ( ( ) => {
84+ if ( initCalled . current && ( window as WindowWithUserData ) . _OX_USER_DATA ?. uuid !== props . userUuid ) {
85+ Sentry . setUser ( { uuid : props . userUuid } ) ;
86+ }
87+ } , [ props . userUuid ] ) ;
88+
7689 // There are two references to the render element here because the Sentry fallback (and
7790 // onError) are not used for unhandledrejection events. To support those events, we provide
7891 // setError in a context to reuse the same error state and render logic.
0 commit comments