-
Notifications
You must be signed in to change notification settings - Fork 45
Open
Labels
Description
1. Problem Statement
The application currently lacks a unified strategy for handling runtime errors and providing feedback to users during asynchronous operations (e.g., API calls, form submissions). Relying on disparate console.log statements or native browser alert() calls results in a disjointed user experience and makes debugging production issues difficult. Furthermore, unhandled errors in specific components can cause the entire application to unmount (white screen of death).
2. Current Behavior / Limitation
- Runtime Crashes: If a generic component throws an error, the entire React component tree crashes, leaving the user with a blank screen.
- Inconsistent Feedback: User feedback is currently handled via scattered
console.logoutputs or blockingwindow.alertpopups. - Lack of Visibility: Silent failures in background processes leave the user unaware that an action (like saving data) has failed.
3. Expected Improvement
- Resilience: Introduction of an Error Boundary to catch JavaScript errors in the component tree, logging those errors, and displaying a fallback UI instead of crashing the whole app.
- User Feedback: Implementation of a non-intrusive Toast Notification system (via a custom hook) to provide consistent success, error, and warning messages.
- Maintainability: Centralized logic for error handling and notifications, making the codebase easier to manage.
4. Proposed Approach
High-Level Technical Steps
-
Dependencies:
- (Optional) Install a lightweight toast library (e.g.,
react-toastifyorreact-hot-toast) to handle the UI animations, or implement a custom Context-based solution if external dependencies are discouraged.
- (Optional) Install a lightweight toast library (e.g.,
-
Create Error Boundary Component (
src/components/common/ErrorBoundary.jsx):- Implement a React Class Component using
static getDerivedStateFromErrorandcomponentDidCatch. - Design a user-friendly "Something went wrong" fallback UI.
- Implement a React Class Component using
-
Create Notification Hook (
src/hooks/useNotification.js):- Create a wrapper hook that exposes methods like
notifySuccess(msg),notifyError(msg), andnotifyInfo(msg). - Ensure this abstracts the underlying library/logic so it can be easily swapped later.
- Create a wrapper hook that exposes methods like
-
Integration (
src/App.js):- Wrap the main application content within the
<ErrorBoundary>. - If using a Toast Context/Provider, wrap the application at the root level alongside the Error Boundary.
- Wrap the main application content within the
Labels: ECWoC26
Reactions are currently unavailable