ai-chatbot/components/ui/client-error-boundary.tsx
Your Name 4533af1495
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled
fix: guard agent workspace client errors
2026-03-17 21:57:36 +08:00

39 lines
778 B
TypeScript

"use client";
import React from "react";
interface ClientErrorBoundaryProps {
children: React.ReactNode;
fallback: React.ReactNode;
}
interface ClientErrorBoundaryState {
hasError: boolean;
}
export class ClientErrorBoundary extends React.Component<
ClientErrorBoundaryProps,
ClientErrorBoundaryState
> {
constructor(props: ClientErrorBoundaryProps) {
super(props);
this.state = { hasError: false };
}
static getDerivedStateFromError() {
return { hasError: true };
}
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
console.error("[ClientErrorBoundary] Caught client error:", error, errorInfo);
}
render() {
if (this.state.hasError) {
return this.props.fallback;
}
return this.props.children;
}
}