1// SPDX-License-Identifier: GPL-2.0-only
2// Copyright (c) 2026-present FERS Contributors (see AUTHORS.md).
4import React from 'react';
6interface ViewportErrorBoundaryProps {
7 children: React.ReactNode;
8 fallback?: React.ReactNode;
9 onError?: (error: Error) => void;
10 resetKey?: string | number;
13interface ViewportErrorBoundaryState {
17export class ViewportErrorBoundary extends React.Component<
18 ViewportErrorBoundaryProps,
19 ViewportErrorBoundaryState
21 override state: ViewportErrorBoundaryState = {
25 static getDerivedStateFromError(): ViewportErrorBoundaryState {
31 override componentDidCatch(error: Error): void {
32 this.props.onError?.(error);
35 override componentDidUpdate(
36 prevProps: Readonly<ViewportErrorBoundaryProps>
38 if (this.state.hasError && prevProps.resetKey !== this.props.resetKey) {
39 this.setState({ hasError: false });
43 override render(): React.ReactNode {
44 if (this.state.hasError) {
45 return this.props.fallback ?? null;
48 return this.props.children;