diff --git a/src/components/site-error-boundary.tsx b/src/components/site-error-boundary.tsx index 94ed65d3d7..4732ad27eb 100644 --- a/src/components/site-error-boundary.tsx +++ b/src/components/site-error-boundary.tsx @@ -1,4 +1,4 @@ -import React, { ErrorInfo, useRef, useState } from 'react'; +import React, { type ErrorInfo, useRef, useState } from 'react'; import { ErrorBoundary } from 'react-error-boundary'; import { FormattedMessage } from 'react-intl'; @@ -21,12 +21,12 @@ const SiteErrorBoundary: React.FC = ({ children }) => { const { links } = useSoapboxConfig(); const textarea = useRef(null); - const [error, setError] = useState(); - const [componentStack, setComponentStack] = useState(); + const [error, setError] = useState(); + const [componentStack, setComponentStack] = useState(); const [browser, setBrowser] = useState(); const isProduction = NODE_ENV === 'production'; - const errorText = error + componentStack; + const errorText = String(error) + componentStack; const clearCookies: React.MouseEventHandler = (e) => { localStorage.clear(); @@ -52,16 +52,18 @@ const SiteErrorBoundary: React.FC = ({ children }) => { setError(error); setComponentStack(info.componentStack); - captureSentryException(error, { - tags: { - // Allow page crashes to be easily searched in Sentry. - ErrorBoundary: 'yes', - }, - }); + if (isProduction) { + captureSentryException(error, { + tags: { + // Allow page crashes to be easily searched in Sentry. + ErrorBoundary: 'yes', + }, + }); - import('bowser') - .then(({ default: Bowser }) => setBrowser(Bowser.getParser(window.navigator.userAgent))) - .catch(() => {}); + import('bowser') + .then(({ default: Bowser }) => setBrowser(Bowser.getParser(window.navigator.userAgent))) + .catch(() => {}); + } } function goHome() { @@ -141,29 +143,21 @@ const SiteErrorBoundary: React.FC = ({ children }) => {
{links.get('status') && ( - <> - - - - + + + )} {links.get('help') && ( - <> -
@@ -177,4 +171,20 @@ const SiteErrorBoundary: React.FC = ({ children }) => { ); }; +interface ISiteErrorBoundaryLink { + href: string; + children: React.ReactNode; +} + +function SiteErrorBoundaryLink({ href, children }: ISiteErrorBoundaryLink) { + return ( + <> +