MCPcopy Create free account
hub / github.com/dailydotdev/apps / ErrorBoundary

Class ErrorBoundary

packages/shared/src/components/ErrorBoundary.tsx:21–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19const DOM_MUTATION_ERROR_TOKENS = ['removeChild', 'insertBefore'] as const;
20
21export class ErrorBoundary extends Component<
22 ErrorBoundaryProps,
23 ErrorBoundaryState
24> {
25 // eslint-disable-next-line react/static-property-placement
26 static contextType = getLogContextStatic();
27
28 // eslint-disable-next-line react/static-property-placement
29 context!: React.ContextType<ReturnType<typeof getLogContextStatic>>;
30
31 constructor(props: ErrorBoundaryProps) {
32 super(props);
33
34 this.state = { hasError: false };
35 }
36
37 static getDerivedStateFromError(): ErrorBoundaryState {
38 return { hasError: true };
39 }
40
41 componentDidCatch(error: Error, errorInfo: ErrorInfo): void {
42 const { logEvent } = this.context;
43 const { feature } = this.props;
44 const isDomMutationError = DOM_MUTATION_ERROR_TOKENS.some((token) =>
45 error.message.includes(token),
46 );
47
48 if (!logEvent) {
49 return;
50 }
51
52 logEvent({
53 event_name: LogEvent.GlobalError,
54 extra: JSON.stringify({
55 msg: error.message,
56 url: window.location.href,
57 error,
58 stack: error?.stack,
59 componentStack: errorInfo.componentStack,
60 digest: errorInfo.digest,
61 feature,
62 domMutation: isDomMutationError || undefined,
63 }),
64 });
65 }
66
67 render(): ReactNode {
68 const { hasError } = this.state;
69 const { children, fallback } = this.props;
70
71 if (hasError) {
72 if (fallback) {
73 return fallback;
74 }
75
76 return <NextError statusCode={0} />;
77 }
78

Callers

nothing calls this directly

Calls 1

getLogContextStaticFunction · 0.90

Tested by

no test coverage detected