Skip to content

Commit c4b0b8b

Browse files
aanishsclaude
andcommitted
fix: auto-retry the startup error boundary on focus/online so a recovered backend un-sticks the app
Refs #3513 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
1 parent 4abf8b4 commit c4b0b8b

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

‎apps/web/src/routes/__root.tsx‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
type ErrorComponentProps,
88
useLocation,
99
useNavigate,
10+
useRouter,
1011
} from "@tanstack/react-router";
1112
import { useEffect, useEffectEvent, useRef, useState } from "react";
1213

@@ -188,6 +189,36 @@ function RootRouteErrorView({ error, reset }: ErrorComponentProps) {
188189
const message = errorMessage(error);
189190
const details = errorDetails(error);
190191

192+
// The root error boundary is shown when beforeLoad's startup probe
193+
// (resolveInitialServerAuthGateState -> fetchSessionState) throws. That failure
194+
// is frequently transient (backend still starting, a flaky session call), but
195+
// the boundary persists until a manual reload. Auto-retry when the window
196+
// regains focus/visibility or the network returns, so a recovered backend
197+
// un-sticks the app instead of stranding the user here. reset() only resets the
198+
// boundary; router.invalidate() re-runs beforeLoad. See #3513.
199+
const router = useRouter();
200+
const retryingRef = useRef(false);
201+
useEffect(() => {
202+
const retry = () => {
203+
if (retryingRef.current) return;
204+
retryingRef.current = true;
205+
void router.invalidate().finally(() => {
206+
retryingRef.current = false;
207+
});
208+
};
209+
const retryIfVisible = () => {
210+
if (document.visibilityState === "visible") retry();
211+
};
212+
document.addEventListener("visibilitychange", retryIfVisible);
213+
window.addEventListener("focus", retry);
214+
window.addEventListener("online", retry);
215+
return () => {
216+
document.removeEventListener("visibilitychange", retryIfVisible);
217+
window.removeEventListener("focus", retry);
218+
window.removeEventListener("online", retry);
219+
};
220+
}, [router]);
221+
191222
return (
192223
<div className="relative flex min-h-screen items-center justify-center overflow-hidden bg-background px-4 py-10 text-foreground sm:px-6">
193224
<div className="pointer-events-none absolute inset-0 opacity-80">

0 commit comments

Comments
 (0)