refactor(client): Embed error boundary into `AppRoot` (#28393)
parent
e4bfde3cfc
commit
262dcaa6dd
File diff suppressed because one or more lines are too long
@ -1,18 +0,0 @@ |
||||
import Bugsnag from '@bugsnag/js'; |
||||
import BugsnagPluginReact from '@bugsnag/plugin-react'; |
||||
import type { ReactElement } from 'react'; |
||||
import React, { Fragment } from 'react'; |
||||
|
||||
import pkg from '../../../package.json'; |
||||
|
||||
const ErrorBoundary = Bugsnag.getPlugin('react')?.createErrorBoundary(React) || Fragment; |
||||
|
||||
Bugsnag.start({ |
||||
apiKey: (window as any).__BUGSNAG_KEY__, |
||||
appVersion: pkg.version, |
||||
plugins: [new BugsnagPluginReact()], |
||||
}); |
||||
|
||||
const BugsnagErrorBoundary = ({ children }: { children: ReactElement }): ReactElement => <ErrorBoundary>{children}</ErrorBoundary>; |
||||
|
||||
export default BugsnagErrorBoundary; |
||||
@ -0,0 +1,23 @@ |
||||
import { Box, States, StatesIcon, StatesSubtitle, StatesTitle } from '@rocket.chat/fuselage'; |
||||
import type { ErrorInfo, ReactElement } from 'react'; |
||||
import React from 'react'; |
||||
|
||||
type AppErrorPageProps = { |
||||
error: Error; |
||||
info?: ErrorInfo; |
||||
clearError: () => void; |
||||
}; |
||||
|
||||
const AppErrorPage = (_props: AppErrorPageProps): ReactElement => { |
||||
return ( |
||||
<Box display='flex' justifyContent='center' height='full' backgroundColor='surface'> |
||||
<States> |
||||
<StatesIcon name='error-circle' /> |
||||
<StatesTitle>Application Error</StatesTitle> |
||||
<StatesSubtitle>The application GUI just crashed.</StatesSubtitle> |
||||
</States> |
||||
</Box> |
||||
); |
||||
}; |
||||
|
||||
export default AppErrorPage; |
||||
@ -0,0 +1,46 @@ |
||||
import Bugsnag from '@bugsnag/js'; |
||||
import type { BugsnagErrorBoundary as BugsnagErrorBoundaryComponent } from '@bugsnag/plugin-react'; |
||||
import BugsnagPluginReact from '@bugsnag/plugin-react'; |
||||
import type { ReactNode } from 'react'; |
||||
import React from 'react'; |
||||
import { ErrorBoundary } from 'react-error-boundary'; |
||||
|
||||
import { Info } from '../../../app/utils/client'; |
||||
import AppErrorPage from './AppErrorPage'; |
||||
|
||||
declare global { |
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
interface Window { |
||||
__BUGSNAG_KEY__: string; |
||||
} |
||||
} |
||||
|
||||
let BugsnagErrorBoundary: BugsnagErrorBoundaryComponent | undefined; |
||||
|
||||
if (window.__BUGSNAG_KEY__) { |
||||
Bugsnag.start({ |
||||
apiKey: window.__BUGSNAG_KEY__, |
||||
appVersion: Info.version, |
||||
plugins: [new BugsnagPluginReact()], |
||||
}); |
||||
|
||||
BugsnagErrorBoundary = Bugsnag.getPlugin('react')?.createErrorBoundary(React); |
||||
} |
||||
|
||||
type OutermostErrorBoundaryProps = { |
||||
children: ReactNode; |
||||
}; |
||||
|
||||
const OutermostErrorBoundary = ({ children }: OutermostErrorBoundaryProps) => { |
||||
if (BugsnagErrorBoundary) { |
||||
return <BugsnagErrorBoundary FallbackComponent={AppErrorPage}>{children}</BugsnagErrorBoundary>; |
||||
} |
||||
|
||||
return ( |
||||
<ErrorBoundary fallbackRender={({ error, resetErrorBoundary }) => <AppErrorPage error={error} clearError={resetErrorBoundary} />}> |
||||
{children} |
||||
</ErrorBoundary> |
||||
); |
||||
}; |
||||
|
||||
export default OutermostErrorBoundary; |
||||
Loading…
Reference in new issue