-
Notifications
You must be signed in to change notification settings - Fork 0
Add production-grade React Error Boundaries with multi-level isolation to all pages #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com>
…ability Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot What about other pages?
…contact, legal) Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com>
Added error boundaries to all pages! Each route now has its own error handler with Sentry location tags: Protected pages:
Public pages:
Also added two-level ErrorBoundary wrapping to the public layout (matching the protected layout pattern). All pages now have consistent error handling with better error tracking in Sentry. Commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements a comprehensive error boundary strategy to prevent component failures from cascading into application-wide crashes. It adds React Error Boundaries at multiple levels (global, app, route, layout, and component) with Sentry integration for production error tracking.
Changes:
- Added reusable ErrorBoundary class component and ErrorFallback UI component with error recovery options
- Implemented Next.js error handlers (global-error.tsx, error.tsx) and route-specific error pages for all major routes
- Enhanced protected and public layouts with two-level error isolation (outer for navbar/footer, inner for page content)
- Added component-level error boundary for AttendanceChart in the dashboard
- Created test page to validate error boundary functionality
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/components/error-boundary.tsx | Core reusable ErrorBoundary class component with Sentry integration and customizable fallback UI |
| src/components/error-fallback.tsx | User-facing error UI with "Try Again" and "Go Home" actions, shows stack traces in development |
| src/app/global-error.tsx | Root-level error handler for critical errors with minimal inline-styled UI |
| src/app/error.tsx | App-level error handler using ErrorFallback component |
| src/app/(protected)/dashboard/error.tsx | Dashboard route error handler with "dashboard" Sentry tag |
| src/app/(protected)/notifications/error.tsx | Notifications route error handler with "notifications" Sentry tag |
| src/app/(protected)/profile/error.tsx | Profile route error handler with "profile" Sentry tag |
| src/app/(protected)/tracking/error.tsx | Tracking route error handler with "tracking" Sentry tag |
| src/app/(public)/contact/error.tsx | Contact route error handler with "contact" Sentry tag |
| src/app/(public)/legal/error.tsx | Legal route error handler with "legal" Sentry tag |
| src/app/(protected)/layout.tsx | Two-level ErrorBoundary wrapping (outer: navbar/footer, inner: children) |
| src/app/(public)/layout.tsx | Two-level ErrorBoundary wrapping (outer: navbar/footer, inner: children) |
| src/app/(protected)/dashboard/DashboardClient.tsx | Component-level ErrorBoundary for AttendanceChart with custom fallback, plus code formatting improvements |
| src/app/(protected)/dashboard/test-error/page.tsx | Test page for validating error boundary behavior |
Comments suppressed due to low confidence (1)
src/app/global-error.tsx:11
- According to Next.js documentation, the global-error.tsx component should accept a reset parameter in addition to the error parameter. This parameter is needed to allow users to reset the error boundary state. The function signature should be:
export default function GlobalError({
error,
reset,
}: {
error: Error & { digest?: string };
reset: () => void;
})Without this parameter, the reset functionality cannot be properly integrated with Next.js's error recovery mechanism.
export default function GlobalError({
error,
}: {
error: Error & { digest?: string };
}) {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…s, update comments, remove dead code Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com>
…te management Co-authored-by: devakesu <61821107+devakesu@users.noreply.github.com>
React Error Boundaries Implementation - ✅ COMPLETE
All requirements from the problem statement have been successfully implemented and validated.
src/components/error-boundary.tsx(reusable ErrorBoundary class component)src/components/error-fallback.tsx(user-friendly fallback UI)src/app/global-error.tsx(improve root-level error handler)src/app/error.tsx(app-level error handler)src/app/(protected)/dashboard/error.tsx(dashboard-specific error handler)src/app/(protected)/notifications/error.tsx(notifications-specific)src/app/(protected)/profile/error.tsx(profile-specific)src/app/(protected)/tracking/error.tsx(tracking-specific)src/app/(public)/contact/error.tsx(contact-specific)src/app/(public)/legal/error.tsx(legal-specific)src/app/(protected)/layout.tsx(add two-level error boundary wrapping)src/app/(public)/layout.tsx(add two-level error boundary wrapping)src/app/(protected)/dashboard/DashboardClient.tsx(wrap AttendanceChart with ErrorBoundary)src/app/(protected)/dashboard/test-error/page.tsx(development-only test page with production protection)📊 Summary
🔧 Recent Improvements
Latest Commit - Global Error Handler:
resetparameter to global-error.tsx for proper error boundary state managementPrevious Commit - Code Quality:
Original prompt
🎯 Objective
Add comprehensive React Error Boundaries to prevent the entire application from crashing when component errors occur. This implements production-grade error handling with user-friendly fallback UI and automatic error reporting to Sentry.
📋 Requirements
1. Create Core Error Boundary Components
File:
src/components/error-boundary.tsxErrorBoundaryclass componentgetDerivedStateFromErrorfor state updatescomponentDidCatchfor error loggingresetErrorfunctionalityFile:
src/components/error-fallback.tsxAlertTrianglefrom lucide-react)/dashboardCard,Buttonfrom shadcn/ui2. Add Next.js Error Pages
File:
src/app/global-error.tsx"use client")<html>and<body>tags (required by Next.js)File:
src/app/error.tsxErrorFallbackcomponent for consistent UIerrorandresetprops from Next.jsFile:
src/app/(protected)/dashboard/error.tsxErrorFallbackcomponent3. Update Protected Layout
File:
src/app/(protected)/layout.tsxErrorBoundaryErrorBoundaryaround the{children}(main content area)4. Component-Level Error Boundaries (Optional but Recommended)
File:
src/app/(protected)/dashboard/DashboardClient.tsxAttendanceChartcomponent withErrorBoundary5. Testing Component (For Development Only)
File:
src/app/(protected)/dashboard/test-error/page.tsx"use client")🎨 Design Requirements
@/components/ui/*🔧 Technical Specifications
Dependencies (Already Installed)
@sentry/nextjs- Already configuredlucide-react- For iconsnext- For routing/navigationError Boundary Behavior
Development Mode:
Production Mode:
Integration Points
sentry.edge.config.tsandsentry.server.config.tsSentry.captureException()for error reportinglocation: "dashboard")✅ Acceptance Criteria
This pull request was created from Copilot chat.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.