diff --git a/packages/docusaurus-theme-classic/src/theme/ErrorPageContent.tsx b/packages/docusaurus-theme-classic/src/theme/ErrorPageContent.tsx index 9a6478126045..f975277a3a4a 100644 --- a/packages/docusaurus-theme-classic/src/theme/ErrorPageContent.tsx +++ b/packages/docusaurus-theme-classic/src/theme/ErrorPageContent.tsx @@ -7,6 +7,10 @@ import React from 'react'; import Translate from '@docusaurus/Translate'; +import { + ErrorBoundaryError, + ErrorBoundaryTryAgainButton, +} from '@docusaurus/theme-common'; import type {Props} from '@theme/Error'; export default function ErrorPageContent({ @@ -24,15 +28,15 @@ export default function ErrorPageContent({ This page crashed. -

{error.message}

-
- +
+ +
+
+
+
diff --git a/packages/docusaurus-theme-common/src/index.ts b/packages/docusaurus-theme-common/src/index.ts index 4c3863016184..3b8e6e7df28d 100644 --- a/packages/docusaurus-theme-common/src/index.ts +++ b/packages/docusaurus-theme-common/src/index.ts @@ -89,3 +89,8 @@ export { SkipToContentFallbackId, SkipToContentLink, } from './utils/skipToContentUtils'; + +export { + ErrorBoundaryTryAgainButton, + ErrorBoundaryError, +} from './utils/errorBoundaryUtils'; diff --git a/packages/docusaurus-theme-common/src/utils/errorBoundaryUtils.module.css b/packages/docusaurus-theme-common/src/utils/errorBoundaryUtils.module.css new file mode 100644 index 000000000000..6b6ecfa607d1 --- /dev/null +++ b/packages/docusaurus-theme-common/src/utils/errorBoundaryUtils.module.css @@ -0,0 +1,11 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +.errorBoundaryError { + white-space: pre-wrap; + color: red; +} diff --git a/packages/docusaurus-theme-common/src/utils/errorBoundaryUtils.tsx b/packages/docusaurus-theme-common/src/utils/errorBoundaryUtils.tsx new file mode 100644 index 000000000000..193ec7cd4ff7 --- /dev/null +++ b/packages/docusaurus-theme-common/src/utils/errorBoundaryUtils.tsx @@ -0,0 +1,28 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import React, {type ComponentProps} from 'react'; +import Translate from '@docusaurus/Translate'; +import styles from './errorBoundaryUtils.module.css'; + +export function ErrorBoundaryTryAgainButton( + props: ComponentProps<'button'>, +): JSX.Element { + return ( + + ); +} + +export function ErrorBoundaryError({error}: {error: Error}): JSX.Element { + return

{error.message}

; +} diff --git a/packages/docusaurus/src/client/theme-fallback/Error/index.tsx b/packages/docusaurus/src/client/theme-fallback/Error/index.tsx index 513348cce4d7..645bd1682bdf 100644 --- a/packages/docusaurus/src/client/theme-fallback/Error/index.tsx +++ b/packages/docusaurus/src/client/theme-fallback/Error/index.tsx @@ -21,16 +21,28 @@ function ErrorDisplay({error, tryAgain}: Props): JSX.Element { display: 'flex', flexDirection: 'column', justifyContent: 'center', - alignItems: 'center', - height: '50vh', + alignItems: 'flex-start', + minHeight: '100vh', width: '100%', + maxWidth: '80ch', fontSize: '20px', + margin: '0 auto', + padding: '1rem', }}> -

This page crashed.

-

{error.message}

- +

{error.message}

); } diff --git a/website/src/components/ErrorBoundaryTestButton/index.tsx b/website/src/components/ErrorBoundaryTestButton/index.tsx index 20ab47ccfe52..e0998291777f 100644 --- a/website/src/components/ErrorBoundaryTestButton/index.tsx +++ b/website/src/components/ErrorBoundaryTestButton/index.tsx @@ -14,7 +14,7 @@ export default function ErrorBoundaryTestButton({ }): JSX.Element { const [state, setState] = useState(false); if (state) { - throw new Error('Boom!'); + throw new Error('Boom!\nSomething bad happened, but you can try again!'); } return (