From 1dff6abb3be01322ae157a092515d3d8982264f6 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Fri, 3 Apr 2026 15:36:11 +0200 Subject: [PATCH] feat: add error boundary to root route for crash resilience Adds a TanStack Router error boundary to the root route so rendering errors or uncaught React Query failures show a friendly error page instead of white-screening the app. The error boundary displays a professional error message with a "Try again" button that resets state and invalidates router data. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/client/routes/__root.tsx | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/client/routes/__root.tsx b/src/client/routes/__root.tsx index 71d9689..221a0fd 100644 --- a/src/client/routes/__root.tsx +++ b/src/client/routes/__root.tsx @@ -1,8 +1,10 @@ import { createRootRoute, + type ErrorComponentProps, Outlet, useMatchRoute, useNavigate, + useRouter, } from "@tanstack/react-router"; import { useState } from "react"; import "../app.css"; @@ -21,8 +23,53 @@ import { useUIStore } from "../stores/uiStore"; export const Route = createRootRoute({ component: RootLayout, + errorComponent: RootErrorBoundary, }); +function RootErrorBoundary({ error, reset }: ErrorComponentProps) { + const router = useRouter(); + + return ( +
+
+
+ + + +
+

+ Something went wrong +

+

+ {error instanceof Error + ? error.message + : "An unexpected error occurred"} +

+ +
+
+ ); +} + function RootLayout() { const navigate = useNavigate(); const { data: auth } = useAuth();