Skip to content

Commit d11efce

Browse files
committed
feat(sanity): refine StudioErrorBoundary component UI
1 parent 7809762 commit d11efce

File tree

1 file changed

+36
-31
lines changed

1 file changed

+36
-31
lines changed

packages/sanity/src/core/studio/StudioErrorBoundary.tsx

+36-31
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
/* eslint-disable i18next/no-literal-string */
22
/* eslint-disable @sanity/i18n/no-attribute-string-literals */
33
import {
4+
Box,
45
Card,
56
Code,
67
Container,
78
ErrorBoundary,
89
type ErrorBoundaryProps,
910
Heading,
1011
Stack,
12+
Text,
1113
} from '@sanity/ui'
1214
import {type ComponentType, type ErrorInfo, type ReactNode, useCallback, useState} from 'react'
15+
import {ErrorActions, isDev, isProd} from 'sanity'
16+
import {styled} from 'styled-components'
1317
import {useHotModuleReload} from 'use-hot-module-reload'
1418

15-
import {Button} from '../../ui-components'
1619
import {SchemaError} from '../config'
1720
import {errorReporter} from '../error/errorReporter'
1821
import {CorsOriginError} from '../store'
@@ -42,15 +45,17 @@ const INITIAL_STATE = {
4245
eventId: null,
4346
} satisfies ErrorBoundaryState
4447

48+
const View = styled(Box)`
49+
align-items: center;
50+
`
51+
4552
export const StudioErrorBoundary: ComponentType<StudioErrorBoundaryProps> = ({
4653
children,
4754
heading = 'An error occurred',
4855
}) => {
4956
const [{error, eventId}, setError] = useState<ErrorBoundaryState>(INITIAL_STATE)
50-
5157
const message = isRecord(error) && typeof error.message === 'string' && error.message
5258
const stack = isRecord(error) && typeof error.stack === 'string' && error.stack
53-
5459
const handleResetError = useCallback(() => setError(INITIAL_STATE), [])
5560
const handleCatchError: ErrorBoundaryProps['onCatch'] = useCallback((params) => {
5661
const report = errorReporter.reportError(params.error, {
@@ -80,37 +85,37 @@ export const StudioErrorBoundary: ComponentType<StudioErrorBoundaryProps> = ({
8085
}
8186

8287
return (
83-
<Card
84-
height="fill"
85-
overflow="auto"
86-
paddingY={[4, 5, 6, 7]}
87-
paddingX={4}
88-
sizing="border"
89-
tone="critical"
90-
>
91-
<Container width={3}>
92-
<Stack space={4}>
93-
{/* TODO: better error boundary */}
94-
95-
<Heading>{heading}</Heading>
96-
97-
<div>
98-
<Button onClick={handleResetError} text="Retry" tone="default" />
99-
</div>
100-
101-
<Card border radius={2} overflow="auto" padding={4} tone="inherit">
88+
<Card height="fill" overflow="auto" paddingY={[4, 5, 6, 7]} paddingX={4} sizing="border">
89+
<View display="flex" height="fill">
90+
<Container width={3}>
91+
<Stack space={6}>
10292
<Stack space={4}>
103-
{message && (
104-
<Code size={1}>
105-
<strong>Error: {message}</strong>
106-
</Code>
93+
<Heading>{heading}</Heading>
94+
<Text>An error occurred that Sanity Studio was unable to recover from.</Text>
95+
{isProd && (
96+
<Text>
97+
<strong>To report this error,</strong> copy the error details and share them with
98+
your development team or Sanity Support.
99+
</Text>
100+
)}
101+
{isDev && (
102+
<Card border radius={2} overflow="auto" padding={4} tone="critical">
103+
<Stack space={4}>
104+
{message && (
105+
<Code size={1}>
106+
<strong>Error: {message}</strong>
107+
</Code>
108+
)}
109+
{stack && <Code size={1}>{stack}</Code>}
110+
{eventId && <Code size={1}>Event ID: {eventId}</Code>}
111+
</Stack>
112+
</Card>
107113
)}
108-
{stack && <Code size={1}>{stack}</Code>}
109-
{eventId && <Code size={1}>Event ID: {eventId}</Code>}
110114
</Stack>
111-
</Card>
112-
</Stack>
113-
</Container>
115+
<ErrorActions error={error} eventId={eventId} onRetry={handleResetError} size="large" />
116+
</Stack>
117+
</Container>
118+
</View>
114119
</Card>
115120
)
116121
}

0 commit comments

Comments
 (0)