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:
@@ -53,7 +53,7 @@ export default function ModPage() {
|
|||||||
{selected && Viewer ? (
|
{selected && Viewer ? (
|
||||||
/* Key by selection path so the Canvas remounts and the camera
|
/* Key by selection path so the Canvas remounts and the camera
|
||||||
refits to the newly selected object. */
|
refits to the newly selected object. */
|
||||||
<ErrorBoundary>
|
<ErrorBoundary key={selectedPath}>
|
||||||
<Suspense
|
<Suspense
|
||||||
fallback={
|
fallback={
|
||||||
<div className="flex h-full items-center justify-center text-sm text-zinc-500">
|
<div className="flex h-full items-center justify-center text-sm text-zinc-500">
|
||||||
@@ -61,7 +61,7 @@ export default function ModPage() {
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Viewer key={selectedPath} object={selected.object} fill />
|
<Viewer object={selected.object} fill />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@@ -27,17 +27,21 @@ export default class ErrorBoundary extends Component<Props, State> {
|
|||||||
console.error('Part viewer error:', error, info.componentStack);
|
console.error('Part viewer error:', error, info.componentStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private retry = () => {
|
||||||
|
this.setState({ error: null });
|
||||||
|
};
|
||||||
|
|
||||||
override render() {
|
override render() {
|
||||||
if (this.state.error) {
|
if (this.state.error) {
|
||||||
return this.props.fallback
|
return this.props.fallback
|
||||||
? this.props.fallback(this.state.error)
|
? this.props.fallback(this.state.error)
|
||||||
: <DefaultFallback error={this.state.error} />;
|
: <DefaultFallback error={this.state.error} onRetry={this.retry} />;
|
||||||
}
|
}
|
||||||
return this.props.children;
|
return this.props.children;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function DefaultFallback({ error }: { error: Error }) {
|
function DefaultFallback({ error, onRetry }: { error: Error; onRetry: () => void }) {
|
||||||
return (
|
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">
|
<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>
|
<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}
|
{error.stack}
|
||||||
</pre>
|
</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>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user