fix(web): preserve session view on polling errors and add missing link mock

Polling errors no longer throw to the error boundary when a session is
already loaded, preventing transient network blips from unmounting the
view. Added missing next/link mock in error.test.tsx.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ashish Huddar 2026-04-06 00:53:45 +05:30
parent 52bcce8f2b
commit 7ea30205b5
2 changed files with 14 additions and 1 deletions

View File

@ -7,6 +7,15 @@ vi.mock("next/navigation", () => ({
useRouter: () => ({ refresh }),
}));
vi.mock("next/link", () => ({
default: ({
children,
...props
}: React.PropsWithChildren<React.AnchorHTMLAttributes<HTMLAnchorElement>>) => (
<a {...props}>{children}</a>
),
}));
import ErrorPage from "./error";
describe("Route error boundary", () => {

View File

@ -75,6 +75,7 @@ export default function SessionPage() {
const sessionIsOrchestratorRef = useRef(false);
const resolvedProjectSessionsKeyRef = useRef<string | null>(null);
const prefixByProjectRef = useRef<Map<string, string>>(new Map());
const hasLoadedSessionRef = useRef(false);
// Keep prefixByProjectRef in sync so fetchProjectSessions (stable [] dep) reads latest map
useEffect(() => {
@ -129,9 +130,12 @@ export default function SessionPage() {
setSession(data);
setRouteError(null);
setSessionMissing(false);
hasLoadedSessionRef.current = true;
} catch (err) {
console.error("Failed to fetch session:", err);
setRouteError(err instanceof Error ? err : new Error("Failed to load session"));
if (!hasLoadedSessionRef.current) {
setRouteError(err instanceof Error ? err : new Error("Failed to load session"));
}
} finally {
setLoading(false);
}