Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openstax/ui-components",
"version": "1.18.2",
"version": "1.18.3",
"license": "MIT",
"source": "./src/index.ts",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -35,7 +35,7 @@
"devDependencies": {
"npm-run-all": "^4.1.5",
"@ladle/react": "^2.1.2",
"@openstax/ts-utils": "^1.8.0",
"@openstax/ts-utils": "^1.27.6",
"@playwright/test": "^1.25.0",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.4.8",
Expand Down
15 changes: 14 additions & 1 deletion src/components/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const ErrorBoundary = ({
sentryInit?: Sentry.BrowserOptions;
errorFallbacks?: { [_: string]: JSX.Element }
errorLevels?: { [_: string]: Sentry.SeverityLevel }
userUuid?: string; // Optional user UUID to set in Sentry
}) => {
const [error, setError] = React.useState<SentryError | null>(null);
const errorFallbacks: { [_: string]: JSX.Element } = { ...defaultErrorFallbacks, ...props.errorFallbacks };
Expand All @@ -48,7 +49,12 @@ export const ErrorBoundary = ({
// Optionally re-render with the children so they can display inline errors with <ErrorMessage />
const renderElement = error && renderFallback ? (typedFallback || fallback) : <>{children}</>;

type WindowWithUserData = Window & { _OX_USER_DATA?: User }
type FrontendConfigType = {
releaseId: string;
[key: string]: unknown; // any other properties, can vary depending on the frontend config repository
};

type WindowWithUserData = Window & { _OX_USER_DATA?: User, _OX_FRONTEND_CONFIG?: FrontendConfigType }

React.useEffect(() => {
if (!sentryDsn && !sentryInit) {
Expand All @@ -61,6 +67,7 @@ export const ErrorBoundary = ({
initCalled.current = true;
Sentry.init(sentryInit || {
dsn: sentryDsn,
release: (window as WindowWithUserData)._OX_FRONTEND_CONFIG?.releaseId,
environment: window.location.hostname,
initialScope: {
user: { uuid: (window as WindowWithUserData)._OX_USER_DATA?.uuid },
Expand All @@ -73,6 +80,12 @@ export const ErrorBoundary = ({
});
}, [sentryDsn, sentryInit]);

React.useEffect(() => {
if (initCalled.current && (window as WindowWithUserData)._OX_USER_DATA?.uuid !== props.userUuid) {
Sentry.setUser({ uuid: (window as WindowWithUserData)._OX_USER_DATA?.uuid });
}
}, [props.userUuid]);

// There are two references to the render element here because the Sentry fallback (and
// onError) are not used for unhandledrejection events. To support those events, we provide
// setError in a context to reuse the same error state and render logic.
Expand Down
Loading
Loading