Skip to content

Commit 96a603b

Browse files
authored
Merge pull request #2421 from navikt/error-boundary
Error boundary for UxSignals
2 parents 0ab73d6 + be28d59 commit 96a603b

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

package-lock.json

Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
"pino-pretty": "12.1.0",
8181
"react": "19.1.0",
8282
"react-dom": "19.1.0",
83+
"react-error-boundary": "6.0.0",
8384
"redis": "4.7.0"
8485
}
8586
}

packages/nextjs/src/components/_common/uxsignalsWidget/UxSignalsWidget.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import React, { useEffect } from 'react';
22
import { getCurrentConsent } from '@navikt/nav-dekoratoren-moduler';
3+
import { ErrorBoundary } from 'react-error-boundary';
4+
import { logger } from '@/shared/logger';
35
import { EditorHelp } from 'components/_editor-only/editorHelp/EditorHelp';
46

57
import style from './UxSignalsWidget.module.scss';
@@ -19,7 +21,7 @@ type Consent = {
1921
const uxSignalsScriptUrl = 'https://widget.uxsignals.com/embed.js';
2022
let scriptAddTimeout: ReturnType<typeof setTimeout>;
2123

22-
export const UxSignalsWidget = ({ embedCode }: UxSignalsWidgetProps) => {
24+
const UxSignalsWidgetComponent = ({ embedCode }: UxSignalsWidgetProps) => {
2325
// If the cookie banner is visible, the user has not taken any action yet.
2426
// Wait and see if the user takes action before adding the script if consent is given..
2527
const checkConsentOrWait = (tries: number = 0) => {
@@ -73,3 +75,14 @@ export const UxSignalsWidget = ({ embedCode }: UxSignalsWidgetProps) => {
7375
</aside>
7476
);
7577
};
78+
79+
export const UxSignalsWidget = ({ embedCode }: UxSignalsWidgetProps) => (
80+
<ErrorBoundary
81+
fallback={null}
82+
onError={(error) => {
83+
logger.info(`Failed to load UX Signals script - ${error}`);
84+
}}
85+
>
86+
<UxSignalsWidgetComponent embedCode={embedCode} />
87+
</ErrorBoundary>
88+
);

0 commit comments

Comments
 (0)