diff --git a/packages/sanity/src/core/studio/StudioErrorBoundary.tsx b/packages/sanity/src/core/studio/StudioErrorBoundary.tsx index 18e0c2401d5f..a1527debca7b 100644 --- a/packages/sanity/src/core/studio/StudioErrorBoundary.tsx +++ b/packages/sanity/src/core/studio/StudioErrorBoundary.tsx @@ -1,6 +1,7 @@ /* eslint-disable i18next/no-literal-string */ /* eslint-disable @sanity/i18n/no-attribute-string-literals */ import { + Box, Card, Code, Container, @@ -8,11 +9,13 @@ import { type ErrorBoundaryProps, Heading, Stack, + Text, } from '@sanity/ui' import {type ComponentType, type ErrorInfo, type ReactNode, useCallback, useState} from 'react' +import {ErrorActions, isDev, isProd} from 'sanity' +import {styled} from 'styled-components' import {useHotModuleReload} from 'use-hot-module-reload' -import {Button} from '../../ui-components' import {SchemaError} from '../config' import {errorReporter} from '../error/errorReporter' import {CorsOriginError} from '../store' @@ -42,15 +45,17 @@ const INITIAL_STATE = { eventId: null, } satisfies ErrorBoundaryState +const View = styled(Box)` + align-items: center; +` + export const StudioErrorBoundary: ComponentType = ({ children, heading = 'An error occured', }) => { const [{error, eventId}, setError] = useState(INITIAL_STATE) - const message = isRecord(error) && typeof error.message === 'string' && error.message const stack = isRecord(error) && typeof error.stack === 'string' && error.stack - const handleResetError = useCallback(() => setError(INITIAL_STATE), []) const handleCatchError: ErrorBoundaryProps['onCatch'] = useCallback((params) => { const report = errorReporter.reportError(params.error, { @@ -80,37 +85,37 @@ export const StudioErrorBoundary: ComponentType = ({ } return ( - - - - {/* TODO: better error boundary */} - - {heading} - -
-
- - + + + + - {message && ( - - Error: {message} - + {heading} + An error occurred that Sanity Studio was unable to recover from. + {isProd && ( + + To report this error, copy the error details and share them with + your development team or Sanity Support. + + )} + {isDev && ( + + + {message && ( + + Error: {message} + + )} + {stack && {stack}} + {eventId && Event ID: {eventId}} + + )} - {stack && {stack}} - {eventId && Event ID: {eventId}} - -
-
+ + + +
) }