This commit is contained in:
Morten Olsen
2023-06-19 16:40:30 +02:00
parent 5c23cef034
commit 673df20514
4 changed files with 47 additions and 4 deletions

View File

@@ -65,7 +65,7 @@ const Board: React.FC<BoardProps> = ({ board, id }) => {
))} ))}
</Masonry> </Masonry>
</View> </View>
</View> </Wrapper>
); );
}; };

View File

@@ -0,0 +1,35 @@
import React from 'react';
type State = {
hasError: boolean;
error?: unknown;
};
type Props = {
children: React.ReactNode;
};
class ErrorBoundary extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = { hasError: false };
}
static getDerivedStateFromError(error: unknown) {
return { hasError: true, error };
}
componentDidCatch(error: any, errorInfo: any) {
console.error('componentDidCatch', error, errorInfo);
}
render() {
if (this.state.hasError) {
return <h1>Something went wrong.</h1>;
}
return this.props.children;
}
}
export { ErrorBoundary };

View File

@@ -4,3 +4,4 @@ export * from './notifications';
export * from './widget'; export * from './widget';
export * from './board'; export * from './board';
export * from './app'; export * from './app';
export * from './error';

View File

@@ -19,6 +19,7 @@ import { DropdownMenu } from '../../base';
import { useCallback, useMemo, useState } from 'react'; import { useCallback, useMemo, useState } from 'react';
import { Typography } from '../../typography'; import { Typography } from '../../typography';
import { NotificationView } from './notification'; import { NotificationView } from './notification';
import { ErrorBoundary } from '../error';
type WidgetProps = { type WidgetProps = {
id: string; id: string;
@@ -129,7 +130,9 @@ const Widget: React.FC<WidgetProps> = ({
<Dialog.Overlay /> <Dialog.Overlay />
<Dialog.Content maxWidth="90vw" height="90vh"> <Dialog.Content maxWidth="90vw" height="90vh">
<Dialog.CloseButton /> <Dialog.CloseButton />
<WidgetView /> <ErrorBoundary>
<WidgetView />
</ErrorBoundary>
</Dialog.Content> </Dialog.Content>
</Dialog.Portal> </Dialog.Portal>
</Dialog> </Dialog>
@@ -169,7 +172,9 @@ const Widget: React.FC<WidgetProps> = ({
> >
<Wrapper className={className} $fr> <Wrapper className={className} $fr>
<WidgetWrapper $f={1}> <WidgetWrapper $f={1}>
<WidgetView /> <ErrorBoundary>
<WidgetView />
</ErrorBoundary>
</WidgetWrapper> </WidgetWrapper>
</Wrapper> </Wrapper>
</motion.div> </motion.div>
@@ -179,7 +184,9 @@ const Widget: React.FC<WidgetProps> = ({
<Dialog.Content> <Dialog.Content>
<Dialog.Title>Edit Widget</Dialog.Title> <Dialog.Title>Edit Widget</Dialog.Title>
<Dialog.Description> <Dialog.Description>
<WidgetEditor onSave={onSave} /> <ErrorBoundary>
<WidgetEditor onSave={onSave} />
</ErrorBoundary>
</Dialog.Description> </Dialog.Description>
</Dialog.Content> </Dialog.Content>
</Dialog.Portal> </Dialog.Portal>