Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix: auto-retry the startup error boundary on focus/online so a recovered backend un-sticks the app #3520

Closedaanishs(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/3520/headopened View on GitHub

Showing 1 changed file with 31 additions and 0 deletions.

x
0 of 1 viewed, 1 left
31 additions and 0 deletionsapps/web/src/routes/__root.tsxModified
View file
@@ -7,6 +7,7 @@
type ErrorComponentProps,
useLocation,
useNavigate,
+ useRouter,
} from "@tanstack/react-router";
import { useEffect, useEffectEvent, useRef, useState } from "react";
​
@@ -188,6 +189,36 @@
const message = errorMessage(error);
const details = errorDetails(error);
​
+ // The root error boundary is shown when beforeLoad's startup probe
+ // (resolveInitialServerAuthGateState -> fetchSessionState) throws. That failure
+ // is frequently transient (backend still starting, a flaky session call), but
+ // the boundary persists until a manual reload. Auto-retry when the window
+ // regains focus/visibility or the network returns, so a recovered backend
+ // un-sticks the app instead of stranding the user here. reset() only resets the
+ // boundary; router.invalidate() re-runs beforeLoad. See #3513.
+ const router = useRouter();
+ const retryingRef = useRef(false);
+ useEffect(() => {
+ const retry = () => {
+ if (retryingRef.current) return;
+ retryingRef.current = true;
+ void router.invalidate().finally(() => {
+ retryingRef.current = false;
+ });
+ };