fix: allow recovering from part viewer error
Add a Try again button to the ErrorBoundary fallback and key the ModPage boundary by selection so picking another object clears a stuck error.
This commit is contained in:
@@ -27,17 +27,21 @@ export default class ErrorBoundary extends Component<Props, State> {
|
||||
console.error('Part viewer error:', error, info.componentStack);
|
||||
}
|
||||
|
||||
private retry = () => {
|
||||
this.setState({ error: null });
|
||||
};
|
||||
|
||||
override render() {
|
||||
if (this.state.error) {
|
||||
return this.props.fallback
|
||||
? this.props.fallback(this.state.error)
|
||||
: <DefaultFallback error={this.state.error} />;
|
||||
: <DefaultFallback error={this.state.error} onRetry={this.retry} />;
|
||||
}
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
|
||||
function DefaultFallback({ error }: { error: Error }) {
|
||||
function DefaultFallback({ error, onRetry }: { error: Error; onRetry: () => void }) {
|
||||
return (
|
||||
<div className="flex h-80 flex-col items-center justify-center gap-2 overflow-auto rounded-lg border border-zinc-800 bg-zinc-900 p-4 text-center">
|
||||
<p className="text-sm font-medium text-zinc-200">Couldn't render this part</p>
|
||||
@@ -49,6 +53,12 @@ function DefaultFallback({ error }: { error: Error }) {
|
||||
{error.stack}
|
||||
</pre>
|
||||
)}
|
||||
<button
|
||||
onClick={onRetry}
|
||||
className="mt-2 rounded-lg bg-zinc-100 px-4 py-2 text-sm font-medium text-zinc-900 hover:bg-zinc-300"
|
||||
>
|
||||
Try again
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user