/** * App-level error boundary. * * Catches render/commit-phase exceptions (including DOM reconciliation errors * such as "Failed to execute 'removeChild' on 'Node'", which browser * auto-translation can trigger by mutating React-managed text nodes) so a * single subtree failure degrades to a friendly reload prompt instead of an * uncaught exception that white-screens the admin. */ import React from "react"; import { __ } from "../lib/i18n"; interface ErrorBoundaryProps { children: React.ReactNode; } interface ErrorBoundaryState { hasError: boolean; } export class ErrorBoundary extends React.Component< ErrorBoundaryProps, ErrorBoundaryState > { constructor(props: ErrorBoundaryProps) { super(props); this.state = { hasError: false }; } static getDerivedStateFromError(): ErrorBoundaryState { return { hasError: true }; } componentDidCatch(error: unknown, info: unknown): void { // Keep a console record for support/debugging; not shown to the user. // eslint-disable-next-line no-console console.error("Yatra admin caught a rendering error:", error, info); } private handleReload = (): void => { window.location.reload(); }; render(): React.ReactNode { if (!this.state.hasError) { return this.props.children; } return (
{__( "The page hit an unexpected error and needs to reload. Your data is safe.", "yatra", )}