From 01d553bfea66a4d566b2a4f875833ae4f803ec1c Mon Sep 17 00:00:00 2001 From: Unchained Date: Sat, 21 Mar 2026 13:02:55 +0200 Subject: [PATCH] fix: Add error boundary to handle browser extension errors - Create ErrorBoundary component to catch extension errors - Ignore TronLink and other chrome-extension errors - Prevent extension conflicts from crashing the app --- src/app/layout.tsx | 5 +- src/components/providers/ErrorBoundary.tsx | 63 ++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 src/components/providers/ErrorBoundary.tsx diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 1cd2e40..f2dfb9c 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,5 +1,6 @@ import "./globals.css"; import type { Metadata } from "next"; +import ErrorBoundary from "@/components/providers/ErrorBoundary"; export const metadata: Metadata = { title: { @@ -24,7 +25,9 @@ export default function RootLayout({ return ( - {children} + + {children} + ); diff --git a/src/components/providers/ErrorBoundary.tsx b/src/components/providers/ErrorBoundary.tsx new file mode 100644 index 0000000..26deb7a --- /dev/null +++ b/src/components/providers/ErrorBoundary.tsx @@ -0,0 +1,63 @@ +"use client"; + +import { Component, ErrorInfo, ReactNode } from "react"; + +interface Props { + children: ReactNode; +} + +interface State { + hasError: boolean; + error?: Error; +} + +export default class ErrorBoundary extends Component { + public state: State = { + hasError: false, + }; + + public static getDerivedStateFromError(error: Error): State { + return { hasError: true, error }; + } + + public componentDidCatch(error: Error, errorInfo: ErrorInfo) { + // Ignore browser extension errors + if (error.message?.includes('tron') || + error.message?.includes('chrome-extension') || + error.stack?.includes('chrome-extension')) { + console.warn('Browser extension error ignored:', error.message); + // Reset error state to continue rendering + this.setState({ hasError: false }); + return; + } + + console.error("Uncaught error:", error, errorInfo); + } + + public render() { + if (this.state.hasError) { + // Check if it's an extension error + if (this.state.error?.message?.includes('tron') || + this.state.error?.stack?.includes('chrome-extension')) { + // Silently recover and render children + return this.props.children; + } + + return ( +
+
+

Something went wrong

+ +
+
+ ); + } + + return this.props.children; + } +}