From 5f1a124b53a5a83412e1ee6134ef17cf6e475443 Mon Sep 17 00:00:00 2001 From: LongYinan <3468483+Brooooooklyn@users.noreply.github.com> Date: Wed, 22 Nov 2023 01:52:45 +0000 Subject: [PATCH] fix(core): add error boundary for workspace layout (#5014) https://github.com/toeverything/AFFiNE/assets/3468483/d478bf4f-2be3-4d7d-8d94-aa95c1f74c8e --- .../affine/affine-error-boundary.css.ts | 2 +- .../affine/affine-error-boundary.tsx | 31 ++++++++++++++----- .../core/src/hooks/affine/use-current-user.ts | 2 +- .../core/src/pages/workspace/index.tsx | 9 ++++-- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/packages/frontend/core/src/components/affine/affine-error-boundary.css.ts b/packages/frontend/core/src/components/affine/affine-error-boundary.css.ts index 145b0c6aec..5999d7ec1c 100644 --- a/packages/frontend/core/src/components/affine/affine-error-boundary.css.ts +++ b/packages/frontend/core/src/components/affine/affine-error-boundary.css.ts @@ -15,7 +15,7 @@ export const errorDetailStyle = style({ }); export const errorTitle = style({ - fontSize: '36px', + fontSize: '32px', lineHeight: '44px', fontWeight: 700, }); diff --git a/packages/frontend/core/src/components/affine/affine-error-boundary.tsx b/packages/frontend/core/src/components/affine/affine-error-boundary.tsx index 648e5f1e00..cd576a0ec2 100644 --- a/packages/frontend/core/src/components/affine/affine-error-boundary.tsx +++ b/packages/frontend/core/src/components/affine/affine-error-boundary.tsx @@ -20,7 +20,7 @@ import { useLocation, useParams } from 'react-router-dom'; import { RecoverableError, - SessionFetchErrorRightAfterLoginOrSignUp, + type SessionFetchErrorRightAfterLoginOrSignUp, } from '../../unexpected-application-state/errors'; import { errorDescription, @@ -33,7 +33,9 @@ import { } from './affine-error-boundary.css'; import errorBackground from './error-status.assets.svg'; -export type AffineErrorBoundaryProps = React.PropsWithChildren; +export type AffineErrorBoundaryProps = React.PropsWithChildren & { + height?: number | string; +}; type AffineError = | QueryParamError @@ -81,7 +83,7 @@ export class AffineErrorBoundary extends Component< if (this.state.error.canRetry()) { this.state.error.retry(); this.setState({ - error: this.state.error, + error: null, canRetryRecoveredError: this.state.error.canRetry(), }); } else { @@ -90,6 +92,10 @@ export class AffineErrorBoundary extends Component< } }; + private readonly handleRefresh = () => { + this.setState({ error: null }); + }; + static getDerivedStateFromError( error: AffineError ): AffineErrorBoundaryState { @@ -121,14 +127,14 @@ export class AffineErrorBoundary extends Component< > > ); - } else if (error instanceof SessionFetchErrorRightAfterLoginOrSignUp) { + } else if (error instanceof RecoverableError) { const retryButtonDesc = this.state.canRetryRecoveredError ? 'Refetch' : 'Reload'; errorDetail = ( <>
+ {error.message ?? error.toString()}
+
+
>
);
}
return (
-