-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Renderer errors log to disk and exceptions during rendering show UI
- Loading branch information
Showing
10 changed files
with
175 additions
and
42 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,14 +1,17 @@ | ||
import { SiteDetailsProvider } from '../hooks/use-site-details'; | ||
import { SiteList } from './site-list'; | ||
import SiteList from './site-list'; | ||
import CreateSiteButton from './create-site-button'; | ||
import ErrorBoundary from './error-boundary'; | ||
|
||
export default function App() { | ||
return ( | ||
<div className="p-8"> | ||
<SiteDetailsProvider> | ||
<CreateSiteButton className="mb-6" /> | ||
<SiteList /> | ||
</SiteDetailsProvider> | ||
<div className="relative p-8 min-h-screen"> | ||
<ErrorBoundary> | ||
<SiteDetailsProvider> | ||
<CreateSiteButton className="mb-6" /> | ||
<SiteList /> | ||
</SiteDetailsProvider> | ||
</ErrorBoundary> | ||
</div> | ||
); | ||
} |
This file contains 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,14 @@ | ||
import Button from './button'; | ||
|
||
export default function DefaultErrorFallback() { | ||
return ( | ||
<div className="flex flex-col items-center gap-4 text-center"> | ||
<h1 className="text-2xl font-light">Something went wrong 😭</h1> | ||
<p className="max-w-md"> | ||
We've logged the issue to help us track down the problem. Reloading <i>might</i> help in the | ||
meantime. | ||
</p> | ||
<Button onClick={ () => window.location.reload() }>Reload</Button> | ||
</div> | ||
); | ||
} |
This file contains 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,28 @@ | ||
import { Component } from 'react'; | ||
import DefaultErrorFallback from './default-error-fallback'; | ||
|
||
interface ErrorLoggerProps { | ||
children: React.ReactNode; | ||
fallback?: React.ReactNode; | ||
} | ||
|
||
export default class ErrorBoundary extends Component< ErrorLoggerProps > { | ||
state = { hasError: false }; | ||
|
||
static getDerivedStateFromError() { | ||
return { hasError: true }; | ||
} | ||
|
||
componentDidCatch( error: Error, info: React.ErrorInfo ) { | ||
// Error will be written to log by the main process | ||
console.error( error, info.componentStack ); | ||
} | ||
|
||
render() { | ||
if ( this.state.hasError ) { | ||
return this.props.fallback || <DefaultErrorFallback />; | ||
} | ||
|
||
return this.props.children; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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