fix(charts): degrade chart failures to one card and heal stale shells per version

The update poller and the chunk-error reload guard key on the target
version instead of disarming for the whole session, so a second deploy
re-arms the self-heal and a stale shell can no longer strand with
404ing chunks. Lazy chart imports retry once and mount inside a
per-card error boundary with a reload affordance — a failed chunk
degrades to one card instead of replacing the page. The JSON API
client attaches a fifteen-second timeout unless the caller brings its
own signal (the raw streaming path is exempt), chart queries surface
errors with a retry instead of rendering as an empty period, per-type
fetch failures reject instead of caching an empty series as fresh, and
the session and snapshot queries retry once on transient network or
server errors.
This commit is contained in:
Marc-André Bombeck committed 2026-06-11 21:17:27 +02:00
1 parent b346e78cc7
commit b5e799c2d6
27 files changed
+892 -89

No files matched your search

@@ -0,0 +1,43 @@
/**
* v1.16.8 — the auth cell retries ONCE on transient failures.
*
* `useAuth` used to pin `retry: false`, so one transient network blip
* on `/api/auth/me` flipped `isAuthenticated` false and sent the shell
* to the redirect spinner mid-session. The cell now uses the shared
* transient-retry predicate: one retry on network errors / 5xx, never
* on 401/403 (those are real answers).
*/
import { afterEach, describe, expect, it, vi } from "vitest";
const useQueryMock = vi.fn<(opts: Record<string, unknown>) => { data: undefined }>(
() => ({ data: undefined }),
);
vi.mock("@tanstack/react-query", () => ({
useQuery: (opts: Record<string, unknown>) => useQueryMock(opts),
useQueryClient: () => ({}),
useMutation: () => ({ mutate: () => undefined, isPending: false }),
}));
vi.mock("next/navigation", () => ({
useRouter: () => ({ push: () => undefined }),
}));
import { useAuth } from "../use-auth";
import { retryOnceOnTransientError } from "@/lib/queries/retry-transient";
import { queryKeys } from "@/lib/query-keys";
afterEach(() => {
useQueryMock.mockClear();
});
describe("useAuth — transient-retry softening", () => {
it("routes retry through the shared transient predicate", () => {
useAuth();
expect(useQueryMock).toHaveBeenCalledTimes(1);
const opts = useQueryMock.mock.calls[0]![0];
expect(opts.retry).toBe(retryOnceOnTransientError);
expect(opts.queryKey).toEqual(queryKeys.authMe());
});
});
+5 -1
View File
@@ -5,6 +5,7 @@ import { useRouter } from "next/navigation";
import { toast } from "sonner";
import { queryKeys } from "@/lib/query-keys";
import { apiGet, apiFetchRaw } from "@/lib/api/api-fetch";
import { retryOnceOnTransientError } from "@/lib/queries/retry-transient";
import { useTranslations } from "@/lib/i18n/context";
import type { TimeFormatPreference } from "@/lib/format-locale";
import { isTimeFormatPreference, storeTimeFormat } from "@/lib/time-format";
@@ -127,7 +128,10 @@ export function useAuth() {
// `queryKeys.auth()` invalidations.
queryKey: queryKeys.authMe(),
queryFn: fetchMe,
retry: false,
// v1.16.8 — one retry on network errors / 5xx (never 401/403). A
// single transient failure used to flip `isAuthenticated` false and
// send the shell to the redirect spinner mid-session.
retry: retryOnceOnTransientError,
staleTime: 5 * 60 * 1000,
});