polish(core): better styling for error screens (#8736)

Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
This commit is contained in:
Tanner Dolby 2023-03-09 08:13:19 -07:00 committed by GitHub
parent e21591c073
commit 7961c5b8d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 52 additions and 12 deletions

View file

@ -7,7 +7,10 @@
import React from 'react'; import React from 'react';
import Translate from '@docusaurus/Translate'; import Translate from '@docusaurus/Translate';
import {ErrorBoundaryTryAgainButton} from '@docusaurus/theme-common'; import {
ErrorBoundaryError,
ErrorBoundaryTryAgainButton,
} from '@docusaurus/theme-common';
import type {Props} from '@theme/Error'; import type {Props} from '@theme/Error';
import Heading from '@theme/Heading'; import Heading from '@theme/Heading';
@ -26,9 +29,15 @@ export default function ErrorPageContent({
This page crashed. This page crashed.
</Translate> </Translate>
</Heading> </Heading>
<p>{error.message}</p> <div className="margin-vert--lg">
<div> <ErrorBoundaryTryAgainButton
<ErrorBoundaryTryAgainButton onClick={tryAgain} /> onClick={tryAgain}
className="button button--primary shadow--lw"
/>
</div>
<hr />
<div className="margin-vert--md">
<ErrorBoundaryError error={error} />
</div> </div>
</div> </div>
</div> </div>

View file

@ -96,4 +96,7 @@ export {
UnlistedMetadata, UnlistedMetadata,
} from './utils/unlistedUtils'; } from './utils/unlistedUtils';
export {ErrorBoundaryTryAgainButton} from './utils/errorBoundaryUtils'; export {
ErrorBoundaryTryAgainButton,
ErrorBoundaryError,
} from './utils/errorBoundaryUtils';

View file

@ -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;
}

View file

@ -7,6 +7,7 @@
import React, {type ComponentProps} from 'react'; import React, {type ComponentProps} from 'react';
import Translate from '@docusaurus/Translate'; import Translate from '@docusaurus/Translate';
import styles from './errorBoundaryUtils.module.css';
export function ErrorBoundaryTryAgainButton( export function ErrorBoundaryTryAgainButton(
props: ComponentProps<'button'>, props: ComponentProps<'button'>,
@ -21,3 +22,7 @@ export function ErrorBoundaryTryAgainButton(
</button> </button>
); );
} }
export function ErrorBoundaryError({error}: {error: Error}): JSX.Element {
return <p className={styles.errorBoundaryError}>{error.message}</p>;
}

View file

@ -21,16 +21,28 @@ function ErrorDisplay({error, tryAgain}: Props): JSX.Element {
display: 'flex', display: 'flex',
flexDirection: 'column', flexDirection: 'column',
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'flex-start',
height: '50vh', minHeight: '100vh',
width: '100%', width: '100%',
maxWidth: '80ch',
fontSize: '20px', fontSize: '20px',
margin: '0 auto',
padding: '1rem',
}}> }}>
<h1>This page crashed.</h1> <h1 style={{fontSize: '3rem'}}>This page crashed</h1>
<p>{error.message}</p> <button
<button type="button" onClick={tryAgain}> type="button"
onClick={tryAgain}
style={{
margin: '1rem 0',
fontSize: '2rem',
cursor: 'pointer',
borderRadius: 20,
padding: '1rem',
}}>
Try again Try again
</button> </button>
<p style={{whiteSpace: 'pre-wrap'}}>{error.message}</p>
</div> </div>
); );
} }

View file

@ -14,7 +14,7 @@ export default function ErrorBoundaryTestButton({
}): JSX.Element { }): JSX.Element {
const [state, setState] = useState(false); const [state, setState] = useState(false);
if (state) { if (state) {
throw new Error('Boom!'); throw new Error('Boom!\nSomething bad happened, but you can try again!');
} }
return ( return (
<button type="button" onClick={() => setState(true)}> <button type="button" onClick={() => setState(true)}>

View file

@ -31,7 +31,6 @@ const EXPECTED_CSS_MARKERS = [
// See https://github.com/facebook/docusaurus/pull/6222 // See https://github.com/facebook/docusaurus/pull/6222
'.markdown>h2', '.markdown>h2',
'.button--outline.button--active', '.button--outline.button--active',
'.DocSearch-Hit-content-wrapper',
'--ifm-color-scheme:light', '--ifm-color-scheme:light',
'.col[class*=col--]', '.col[class*=col--]',
'.padding-vert--xl', '.padding-vert--xl',
@ -49,6 +48,7 @@ const EXPECTED_CSS_MARKERS = [
// Lazy-loaded lib // Lazy-loaded lib
'.DocSearch-Modal', '.DocSearch-Modal',
'.DocSearch-Hit-content-wrapper',
]; ];
const cssDirName = fileURLToPath(new URL('build/assets/css', import.meta.url)); const cssDirName = fileURLToPath(new URL('build/assets/css', import.meta.url));