Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
28 changes: 4 additions & 24 deletions apps/web/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import * as Sentry from '@sentry/nextjs';
import type { Metadata, Viewport } from 'next';
import { cookies } from 'next/headers';
import { Toaster } from 'react-hot-toast';

import AnalyticsWrapper from '@/shared/components/AnalyticsWrapper';
import { PushSubscriptionEffect } from '@/shared/hooks/PushSubscriptionEffect';
import ThirdPartyWrappers from '@/shared/thirdparty/ThirdPartyWrappers';

import { Providers } from './providers';

Expand Down Expand Up @@ -32,26 +29,9 @@ export default async function RootLayout({ children }: { children: React.ReactNo
return (
<html lang="ko" className={`${isDark ? 'dark' : ''} bg-[#F5F5F5]`}>
<body className={`mx-auto max-w-[375px]`}>
<Sentry.ErrorBoundary fallback={<p>An error has occurred</p>}>
<Providers>
<PushSubscriptionEffect />
{children}
<Toaster
position="bottom-center"
toastOptions={{
duration: 2300,
style: {
background: '#484848',
color: '#f5f5f5',
borderRadius: '8px',
boxShadow: '0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)',
fontSize: 12,
},
}}
/>
<AnalyticsWrapper />
</Providers>
</Sentry.ErrorBoundary>
<Providers>
<ThirdPartyWrappers>{children}</ThirdPartyWrappers>
</Providers>
</body>
</html>
);
Expand Down
17 changes: 17 additions & 0 deletions apps/web/shared/thirdparty/SentryErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use client';

import { useEffect, useState } from 'react';

export default function LazySentryBoundary({ children }: { children: React.ReactNode }) {
const [Boundary, setBoundary] = useState<React.ComponentType<any> | null>(null);

useEffect(() => {
// 첫 페인트 이후 로드
if (process.env.NODE_ENV === 'production') {
import('@sentry/nextjs').then((mod) => setBoundary(() => mod.ErrorBoundary));
}
}, []);

if (!Boundary) return <>{children}</>; // 초기 페인트는 그냥 통과
return <Boundary fallback={<p>An error has occurred</p>}>{children}</Boundary>;
}
32 changes: 32 additions & 0 deletions apps/web/shared/thirdparty/ThirdPartyWrappers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use client';

import React from 'react';

import { Toaster } from 'react-hot-toast';

import { PushSubscriptionEffect } from '@/shared/hooks/PushSubscriptionEffect';
import AnalyticsWrapper from '@/shared/thirdparty/AnalyticsWrapper';
import SentryErrorBoundaryWrapper from '@/shared/thirdparty/SentryErrorBoundary';

export default function ThirdPartyWrappers({ children }: { children: React.ReactNode }) {
return (
<SentryErrorBoundaryWrapper>
<PushSubscriptionEffect />
{children}
<Toaster
position="bottom-center"
toastOptions={{
duration: 2300,
style: {
background: '#484848',
color: '#f5f5f5',
borderRadius: '8px',
boxShadow: '0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)',
fontSize: 12,
},
}}
/>
<AnalyticsWrapper />
</SentryErrorBoundaryWrapper>
);
}