@@ -38,6 +38,7 @@ export const ErrorBoundary = ({
38
38
sentryInit ?: Sentry . BrowserOptions ;
39
39
errorFallbacks ?: { [ _ : string ] : JSX . Element }
40
40
errorLevels ?: { [ _ : string ] : Sentry . SeverityLevel }
41
+ userUuid ?: string ; // Optional user UUID to set in Sentry
41
42
} ) => {
42
43
const [ error , setError ] = React . useState < SentryError | null > ( null ) ;
43
44
const errorFallbacks : { [ _ : string ] : JSX . Element } = { ...defaultErrorFallbacks , ...props . errorFallbacks } ;
@@ -48,7 +49,12 @@ export const ErrorBoundary = ({
48
49
// Optionally re-render with the children so they can display inline errors with <ErrorMessage />
49
50
const renderElement = error && renderFallback ? ( typedFallback || fallback ) : < > { children } </ > ;
50
51
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 }
52
58
53
59
React . useEffect ( ( ) => {
54
60
if ( ! sentryDsn && ! sentryInit ) {
@@ -61,6 +67,7 @@ export const ErrorBoundary = ({
61
67
initCalled . current = true ;
62
68
Sentry . init ( sentryInit || {
63
69
dsn : sentryDsn ,
70
+ release : ( window as WindowWithUserData ) . _OX_FRONTEND_CONFIG ?. releaseId ,
64
71
environment : window . location . hostname ,
65
72
initialScope : {
66
73
user : { uuid : ( window as WindowWithUserData ) . _OX_USER_DATA ?. uuid } ,
@@ -73,6 +80,12 @@ export const ErrorBoundary = ({
73
80
} ) ;
74
81
} , [ sentryDsn , sentryInit ] ) ;
75
82
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
+
76
89
// There are two references to the render element here because the Sentry fallback (and
77
90
// onError) are not used for unhandledrejection events. To support those events, we provide
78
91
// setError in a context to reuse the same error state and render logic.
0 commit comments