From 2cdfaf487101711b9244e42db6865e0a24770b2b Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 12 Oct 2023 19:52:28 -0500 Subject: [PATCH] Remove useSentry hook, reorganize in SoapboxHead --- src/hooks/index.ts | 1 - src/init/soapbox-head.tsx | 11 ++++++++--- src/{hooks/useSentry.ts => sentry.ts} | 13 +------------ 3 files changed, 9 insertions(+), 16 deletions(-) rename src/{hooks/useSentry.ts => sentry.ts} (81%) diff --git a/src/hooks/index.ts b/src/hooks/index.ts index ef77478df..1da5fb9e4 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -19,7 +19,6 @@ export { useOwnAccount } from './useOwnAccount'; export { usePrevious } from './usePrevious'; export { useRefEventHandler } from './useRefEventHandler'; export { useRegistrationStatus } from './useRegistrationStatus'; -export { useSentry } from './useSentry'; export { useSettings } from './useSettings'; export { useSoapboxConfig } from './useSoapboxConfig'; export { useSystemTheme } from './useSystemTheme'; diff --git a/src/init/soapbox-head.tsx b/src/init/soapbox-head.tsx index 0039404e0..735e258f1 100644 --- a/src/init/soapbox-head.tsx +++ b/src/init/soapbox-head.tsx @@ -1,14 +1,14 @@ import clsx from 'clsx'; -import React from 'react'; +import React, { useEffect } from 'react'; import { - useSentry, useSettings, useSoapboxConfig, useTheme, useLocale, } from 'soapbox/hooks'; import { normalizeSoapboxConfig } from 'soapbox/normalizers'; +import { startSentry } from 'soapbox/sentry'; import { generateThemeCss } from 'soapbox/utils/theme'; const Helmet = React.lazy(() => import('soapbox/components/helmet')); @@ -26,6 +26,7 @@ const SoapboxHead: React.FC = ({ children }) => { const demo = !!settings.get('demo'); const darkMode = useTheme() === 'dark'; const themeCss = generateThemeCss(demo ? normalizeSoapboxConfig({ brandColor: '#0482d8' }) : soapboxConfig); + const dsn = soapboxConfig.sentryDsn; const bodyClass = clsx('h-full bg-white text-base dark:bg-gray-800', { 'no-reduce-motion': !settings.get('reduceMotion'), @@ -33,7 +34,11 @@ const SoapboxHead: React.FC = ({ children }) => { 'demetricator': settings.get('demetricator'), }); - useSentry(soapboxConfig.sentryDsn); + useEffect(() => { + if (dsn) { + startSentry(dsn).catch(console.error); + } + }, [dsn]); return ( <> diff --git a/src/hooks/useSentry.ts b/src/sentry.ts similarity index 81% rename from src/hooks/useSentry.ts rename to src/sentry.ts index 2a13b2645..a76d432c0 100644 --- a/src/hooks/useSentry.ts +++ b/src/sentry.ts @@ -1,14 +1,3 @@ -import { useEffect } from 'react'; - -/** Hook to start Sentry. Should only be called once. */ -function useSentry(dsn: string | undefined) { - useEffect(() => { - if (dsn) { - startSentry(dsn).catch(console.error); - } - }, [dsn]); -} - /** Start Sentry. */ async function startSentry(dsn: string): Promise { const [Sentry, { Integrations: Integrations }] = await Promise.all([ @@ -47,4 +36,4 @@ async function startSentry(dsn: string): Promise { }); } -export { useSentry }; \ No newline at end of file +export { startSentry }; \ No newline at end of file