Skip to content

feat: implement global React Error Boundary with fallback UI#497

Open
sohaa-khan11 wants to merge 2 commits intoAOSSIE-Org:mainfrom
sohaa-khan11:feature/global-error-boundary
Open

feat: implement global React Error Boundary with fallback UI#497
sohaa-khan11 wants to merge 2 commits intoAOSSIE-Org:mainfrom
sohaa-khan11:feature/global-error-boundary

Conversation

@sohaa-khan11
Copy link

@sohaa-khan11 sohaa-khan11 commented Feb 27, 2026

Addressed Issues:

Fixes #495

Screenshots/Recordings:

Screenshot 2026-02-27 164834

Additional Notes:

This PR introduces a minimal, reusable Global React Error Boundary to improve frontend stability.

  1. It catches rendering, lifecycle, and constructor errors
  2. It prevents full-application crashes caused by runtime exceptions in child components
  3. It does not replace manual error handling for async logic or event handlers.

Checklist

  • My PR addresses a single issue, fixes a single bug or makes a single improvement.
  • My code follows the project's code style and conventions
  • If applicable, I have made corresponding changes or additions to the documentation
  • If applicable, I have made corresponding changes or additions to tests
  • My changes generate no new warnings or errors
  • I have joined the Discord server and I will share a link to this PR with the project maintainers there
  • I have read the Contribution Guidelines
  • Once I submit my PR, CodeRabbit AI will automatically review it and I will address CodeRabbit's comments.

AI Usage Disclosure

Check one of the checkboxes below:

  • This PR does not contain AI-generated code at all.
  • This PR contains AI-generated code. I have tested the code locally and I am responsible for it.

I have used the following AI models and tools:
ChatGPT (for guidance and review assistance)

⚠️ AI Notice - Important!

We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact.

Summary by CodeRabbit

  • New Features
    • Added a user-friendly error fallback screen with a retry option so unexpected errors no longer break the interface.
  • Bug Fixes
    • Improved app stability during navigation and route rendering to reduce runtime failures and preserve user workflow.

@coderabbitai
Copy link

coderabbitai bot commented Feb 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8d22ed5 and c39e7d9.

📒 Files selected for processing (1)
  • eduaid_web/src/utils/ErrorBoundary.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • eduaid_web/src/utils/ErrorBoundary.js

📝 Walkthrough

Walkthrough

Adds a new React ErrorBoundary component and wraps the application's Routes with it in App.js; also renames two imports to camelCase (QuestionType, TextInput) and updates JSX to use the renamed components.

Changes

Cohort / File(s) Summary
Error Boundary Implementation
eduaid_web/src/utils/ErrorBoundary.js
New ErrorBoundary React class with getDerivedStateFromError, componentDidCatch, fallback UI and a Retry handler that reloads the page.
App Wiring & Imports
eduaid_web/src/App.js
Imported ErrorBoundary and renamed imports: Question_TypeQuestionType, Text_InputTextInput. Routes are now rendered inside <ErrorBoundary>...</ErrorBoundary>.

Sequence Diagram(s)

sequenceDiagram
    participant Browser
    participant App as App (Routes)
    participant EB as ErrorBoundary
    participant Page as ChildPageComponent

    Browser->>App: Initial render
    App->>EB: Render Routes (children)
    EB->>Page: Render child component
    alt Child throws error
        Page-->>EB: Error thrown
        EB->>EB: getDerivedStateFromError / componentDidCatch
        EB->>Browser: Render fallback UI (Retry button)
        Browser->>EB: Click Retry
        EB->>Browser: window.location.reload()
    else No error
        Page-->>EB: Renders normally
        EB->>Browser: Display page content
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hopped through routes and watched them bind,
Caught a tumble, saved the user kind.
A button to retry, a nap in the sun—
Errors don't scare this little one! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: implementing a global React Error Boundary with fallback UI, which matches the core functionality added across the modified files.
Linked Issues check ✅ Passed The pull request successfully implements all coding requirements from issue #495: creating a reusable ErrorBoundary component, wrapping Routes in App.js with it, and providing fallback UI with a Retry button.
Out of Scope Changes check ✅ Passed All changes are directly aligned with the linked issue #495 objectives: ErrorBoundary creation, integration into App.js, and fallback UI implementation with no unrelated modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (3)
eduaid_web/src/utils/ErrorBoundary.js (3)

27-52: Add minimal accessibility semantics to the fallback block.

Please add alert semantics so assistive tech announces the error state, and set the button type explicitly.

♿ Proposed refactor
-                <div style={{
+                <div
+                    role="alert"
+                    aria-live="assertive"
+                    style={{
                     display: 'flex',
                     flexDirection: 'column',
                     alignItems: 'center',
                     justifyContent: 'center',
                     height: '100vh',
                     backgroundColor: '#02000F',
                     color: 'white',
                     fontFamily: 'sans-serif'
                 }}>
@@
-                    <button
+                    <button
+                        type="button"
                         onClick={this.handleRetry}
                         style={{
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@eduaid_web/src/utils/ErrorBoundary.js` around lines 27 - 52, The fallback UI
in ErrorBoundary's render (the div containing the error message and the Retry
button) lacks accessibility semantics; add ARIA alert semantics (e.g.,
role="alert" or aria-live="assertive") on the container that holds the
"Something went wrong." text so assistive tech announces the error, and make the
Retry button explicit by adding type="button" to the element that uses
this.handleRetry (the Retry button) to prevent accidental form submission.

19-21: Prefer local boundary reset over full page reload.

Line 20 triggers a hard refresh, which is heavy and resets the whole app session. Resetting boundary state is usually enough to remount children.

♻️ Proposed refactor
-    handleRetry = () => {
-        window.location.reload();
-    };
+    handleRetry = () => {
+        this.setState({ hasError: false });
+    };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@eduaid_web/src/utils/ErrorBoundary.js` around lines 19 - 21, The handleRetry
method in the ErrorBoundary component currently forces a full page reload;
instead update it to reset the boundary's local error state so children remount
without wiping the entire app session. Inside ErrorBoundary.handleRetry set the
internal error-related state (e.g., this.setState({ hasError: false, error:
null, errorInfo: null }) or the equivalent hooks state reset) and ensure any
derived values are cleared so the component re-renders its children rather than
calling window.location.reload().

14-17: Route caught errors to monitoring, not only console.

Consider forwarding error and errorInfo to your error tracking pipeline (e.g., Sentry/LogRocket) so production failures are actionable.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@eduaid_web/src/utils/ErrorBoundary.js` around lines 14 - 17, In
ErrorBoundary.componentDidCatch, replace the sole console.error call by
forwarding the captured error and errorInfo to your monitoring pipeline: import
and call your monitoring client (e.g., Sentry.captureException(error, { extra:
errorInfo }) or LogRocket.log(error, errorInfo)) inside componentDidCatch,
keeping a console.error fallback; ensure you include both `error` and
`errorInfo` when invoking the monitoring API and handle any potential exceptions
from the monitoring call so it doesn't crash the boundary.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@eduaid_web/src/utils/ErrorBoundary.js`:
- Around line 27-52: The fallback UI in ErrorBoundary's render (the div
containing the error message and the Retry button) lacks accessibility
semantics; add ARIA alert semantics (e.g., role="alert" or
aria-live="assertive") on the container that holds the "Something went wrong."
text so assistive tech announces the error, and make the Retry button explicit
by adding type="button" to the element that uses this.handleRetry (the Retry
button) to prevent accidental form submission.
- Around line 19-21: The handleRetry method in the ErrorBoundary component
currently forces a full page reload; instead update it to reset the boundary's
local error state so children remount without wiping the entire app session.
Inside ErrorBoundary.handleRetry set the internal error-related state (e.g.,
this.setState({ hasError: false, error: null, errorInfo: null }) or the
equivalent hooks state reset) and ensure any derived values are cleared so the
component re-renders its children rather than calling window.location.reload().
- Around line 14-17: In ErrorBoundary.componentDidCatch, replace the sole
console.error call by forwarding the captured error and errorInfo to your
monitoring pipeline: import and call your monitoring client (e.g.,
Sentry.captureException(error, { extra: errorInfo }) or LogRocket.log(error,
errorInfo)) inside componentDidCatch, keeping a console.error fallback; ensure
you include both `error` and `errorInfo` when invoking the monitoring API and
handle any potential exceptions from the monitoring call so it doesn't crash the
boundary.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fc3bf1a and 8d22ed5.

📒 Files selected for processing (2)
  • eduaid_web/src/App.js
  • eduaid_web/src/utils/ErrorBoundary.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Implement Global React Error Boundary and Fallback UI in eduaid_web

1 participant