From 815f255ff56976ecdd2d620ca1d827308e0a8210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A8=B8=EB=8B=88=ED=8E=98=EB=8B=88?= Date: Wed, 18 Mar 2026 22:22:29 +0900 Subject: [PATCH] feat: add React ErrorBoundary with retry and reload UI Add class-based ErrorBoundary component that catches rendering errors and shows a user-friendly fallback with retry/reload buttons. Wrap in root layout to protect against full-page crashes. Co-Authored-By: Claude Opus 4.6 --- frontend/src/app/layout.tsx | 5 +- frontend/src/components/error-boundary.tsx | 73 ++++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 frontend/src/components/error-boundary.tsx diff --git a/frontend/src/app/layout.tsx b/frontend/src/app/layout.tsx index 0c93501..2368817 100644 --- a/frontend/src/app/layout.tsx +++ b/frontend/src/app/layout.tsx @@ -3,6 +3,7 @@ import { Inter, Noto_Sans_KR } from 'next/font/google'; import './globals.css'; import { ThemeProvider } from '@/components/providers/theme-provider'; import { Toaster } from '@/components/ui/sonner'; +import { ErrorBoundary } from '@/components/error-boundary'; const inter = Inter({ subsets: ['latin'], @@ -34,7 +35,9 @@ export default function RootLayout({ enableSystem disableTransitionOnChange > - {children} + + {children} + diff --git a/frontend/src/components/error-boundary.tsx b/frontend/src/components/error-boundary.tsx new file mode 100644 index 0000000..007da7a --- /dev/null +++ b/frontend/src/components/error-boundary.tsx @@ -0,0 +1,73 @@ +'use client'; + +import React from 'react'; +import { Button } from '@/components/ui/button'; + +interface ErrorBoundaryProps { + children: React.ReactNode; +} + +interface ErrorBoundaryState { + hasError: boolean; +} + +export class ErrorBoundary extends React.Component { + constructor(props: ErrorBoundaryProps) { + super(props); + this.state = { hasError: false }; + } + + static getDerivedStateFromError(): ErrorBoundaryState { + return { hasError: true }; + } + + componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { + console.error('ErrorBoundary caught an error:', error, errorInfo); + } + + handleRetry = () => { + this.setState({ hasError: false }); + }; + + render() { + if (this.state.hasError) { + return ( +
+
+
+ + + +
+

+ 문제가 발생했습니다 +

+

+ 페이지를 새로고침 해주세요. +

+
+ + +
+
+
+ ); + } + + return this.props.children; + } +}