// // Copyright 2026 DXOS.org // import React, { type PropsWithChildren } from 'react'; import { type FallbackProps } from 'react-error-boundary'; import { safeStringify } from '@dxos/util'; import { translationKey } from '#translations'; import { useTranslation } from '../../primitives'; import { IconButton } from '../Button'; import { ErrorStack } from './ErrorStack'; export type ErrorFallbackProps = PropsWithChildren & { title?: string; data?: any }>; /** * Themed fallback component for `ErrorBoundary`. */ export const ErrorFallback = ({ children, error, title, data }: ErrorFallbackProps) => { const { t } = useTranslation(translationKey); const isDev = process.env.NODE_ENV === 'development'; const message = error instanceof Error ? error.message : String(error); return (

{title ?? 'Runtime Error'}

{message}

{isDev && error instanceof Error && (
{ const text = error instanceof Error ? (error.stack ?? error.message) : String(error); void navigator.clipboard.writeText(text); }} >
)} {data && (
{ void navigator.clipboard.writeText(JSON.stringify(data, undefined, 2)); }} >
{safeStringify(data, undefined, 2)}
)} {children}
); }; const Section = ({ children, title, onClick }: PropsWithChildren<{ title?: string; onClick?: () => void }>) => { return (
{onClick && (
)} {children}
); };