fix(projects): GitHubStatus times out after 15s instead of skeleton-forever

useFetch grew an optional timeoutMs that wires an AbortController to the
underlying fetch and surfaces an "AbortError" as a normal error string so the
caller's existing error branch handles it. GitHubStatus passes 15_000ms — well
under the server's 30s github-status.sh ceiling and short enough that a slow
upstream resolves to FetchErrorState + Retry instead of an indefinite spinner.

Verified live on /projects: at ~13s the skeleton transitions to "Couldn't load
GitHub status / Retry" with no other panels affected.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
g-butandClaude Opus 4.7 committed 2026-05-20 18:13:48 +02:00
1 parent 1d481656e6
commit eed1228770
2 files changed
+21 -5

No files matched your search

+1 -1
View File
@@ -22,7 +22,7 @@ const STATUS_ICONS: Record<string, { icon: typeof CheckCircle; className: string
};
export function GitHubStatus() {
const { data, loading, error, refetch } = useFetch<{ repos: RepoStatus[]; error?: string }>("/api/github", { intervalMs: 2 * 60_000 });
const { data, loading, error, refetch } = useFetch<{ repos: RepoStatus[]; error?: string }>("/api/github", { intervalMs: 2 * 60_000, timeoutMs: 15_000 });
const repos = data?.repos ?? [];
return (
+20 -4
View File
@@ -3,7 +3,10 @@
import { useState, useEffect } from "react";
import { getJson } from "@/lib/api/fetch";
export function useFetch<T>(url: string | null, { intervalMs }: { intervalMs?: number } = {}) {
export function useFetch<T>(
url: string | null,
{ intervalMs, timeoutMs }: { intervalMs?: number; timeoutMs?: number } = {},
) {
const [data, setData] = useState<T | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
@@ -16,21 +19,34 @@ export function useFetch<T>(url: string | null, { intervalMs }: { intervalMs?: n
setLoading(true);
setError(null);
getJson<T>(url)
const controller = timeoutMs ? new AbortController() : null;
const timeoutId = timeoutMs && controller
? setTimeout(() => controller.abort(), timeoutMs)
: null;
getJson<T>(url, controller ? { signal: controller.signal } : undefined)
.then((json) => {
if (!cancelled) setData(json);
})
.catch((err: unknown) => {
if (!cancelled) setError(err instanceof Error ? err.message : "Failed to load");
if (cancelled) return;
if (err instanceof DOMException && err.name === "AbortError") {
setError(`Timed out after ${Math.round((timeoutMs ?? 0) / 1000)}s`);
} else {
setError(err instanceof Error ? err.message : "Failed to load");
}
})
.finally(() => {
if (timeoutId) clearTimeout(timeoutId);
if (!cancelled) setLoading(false);
});
return () => {
cancelled = true;
if (timeoutId) clearTimeout(timeoutId);
controller?.abort();
};
}, [url, revision]);
}, [url, revision, timeoutMs]);
// Silent background refresh — setRevision is stable so no ref needed.
useEffect(() => {