-
Notifications
You must be signed in to change notification settings - Fork 98
feat: implement global React Error Boundary for graceful fallbacks #1149
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
Merged
Itzzavdheshh
merged 1 commit into
itzzavdhesh:main
from
vivek0028:feat/global-error-boundary
Jul 29, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import React from 'react'; | ||
|
|
||
| class ErrorBoundary extends React.Component { | ||
| constructor(props) { | ||
| super(props); | ||
| this.state = { hasError: false, error: null }; | ||
| } | ||
|
|
||
| static getDerivedStateFromError(error) { | ||
| // Update state so the next render will show the fallback UI. | ||
| return { hasError: true, error }; | ||
| } | ||
|
|
||
| componentDidCatch(error, errorInfo) { | ||
| // You can also log the error to an error reporting service | ||
| console.error("ErrorBoundary caught an error:", error, errorInfo); | ||
| } | ||
|
|
||
| handleReload = () => { | ||
| window.location.reload(); | ||
| }; | ||
|
|
||
| render() { | ||
| if (this.state.hasError) { | ||
| return ( | ||
| <div className="flex flex-col items-center justify-center min-h-screen p-6 bg-[var(--bg-page)] text-[var(--text-base)]"> | ||
| <div className="max-w-md w-full p-8 rounded-xl bg-[var(--bg-card)] border border-[var(--border)] shadow-lg flex flex-col items-center text-center"> | ||
| <svg | ||
| className="w-16 h-16 text-red-500 mb-4" | ||
| fill="none" | ||
| stroke="currentColor" | ||
| viewBox="0 0 24 24" | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| > | ||
| <path | ||
| strokeLinecap="round" | ||
| strokeLinejoin="round" | ||
| strokeWidth={2} | ||
| d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" | ||
| /> | ||
| </svg> | ||
| <h2 className="text-2xl font-bold mb-2">Something went wrong</h2> | ||
| <p className="text-[var(--text-muted)] mb-6 break-words w-full"> | ||
| {this.state.error?.message || "An unexpected application error occurred."} | ||
| </p> | ||
| <button | ||
| onClick={this.handleReload} | ||
| className="px-6 py-2 bg-green-500 hover:bg-green-600 text-white font-medium rounded-lg transition-colors" | ||
| > | ||
| Reload Application | ||
| </button> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| return this.props.children; | ||
| } | ||
| } | ||
|
|
||
| export default ErrorBoundary; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.