feat(system): 30s AutoRefresh keeps telemetry card live

RecentFailuresCard (510bfc0) only re-renders on PullToRefresh / focus-return
gestures. A failure that lands NOW is invisible to a user staring at /system
without doing one of those.

Tiny client component: <AutoRefresh intervalMs={30_000} /> mounts a
visibility-gated setInterval that fires router.refresh() — re-fetches all
server cards on the page in one call, no per-card plumbing. Visibility
check skips polling on a backgrounded tab so we're not chewing Neon
queries for nobody.

Composable with the existing PullToRefresh + RefreshOnFocus — router.refresh
is idempotent enough that two near-simultaneous triggers batch into one
React work pass. No coordination logic needed.

Mounted on /system right after RecentFailuresCard.

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-21 03:11:21 +02:00
1 parent 510bfc052a
commit bd8e4fa40d
2 files changed
+32

No files matched your search

+3
View File
@@ -7,6 +7,7 @@ import { RecentFailuresCard } from "@/components/system/RecentFailuresCard";
import { CardSkeleton } from "@/components/ui/card";
import { readCronJobs } from "@/lib/crons";
import { PullToRefresh } from "@/components/shared/PullToRefresh";
import { AutoRefresh } from "@/components/shared/AutoRefresh";
export const metadata = { title: "System" };
@@ -24,6 +25,8 @@ export default function SystemPage() {
<Suspense fallback={<CardSkeleton />}>
<RecentFailuresCard />
</Suspense>
{/* 30s revalidation so debug_logs rows that land NOW appear without manual refresh. */}
<AutoRefresh intervalMs={30_000} />
</PageLayout>
</PullToRefresh>
);
+29
View File
@@ -0,0 +1,29 @@
"use client";
import { useEffect } from "react";
import { useRouter } from "next/navigation";
/**
* Mounts a setInterval that calls router.refresh() so server-component cards
* on the page stay fresh without manual gestures. Visibility-gated — won't
* poll while the tab is hidden (saves bandwidth on a backgrounded tab).
*
* Use case: /system's RecentFailuresCard reads debug_logs server-side once
* per render. A failure that lands NOW is invisible until the user gestures
* a refresh. Mount <AutoRefresh /> next to the card to close that window.
*
* Stateless. Renders null. Composable with PullToRefresh + RefreshOnFocus —
* each is its own trigger; they don't fight (router.refresh is idempotent
* if called multiple times in quick succession; Next batches the work).
*/
export function AutoRefresh({ intervalMs = 30_000 }: { intervalMs?: number }) {
const router = useRouter();
useEffect(() => {
const id = setInterval(() => {
if (document.visibilityState !== "visible") return;
router.refresh();
}, intervalMs);
return () => clearInterval(id);
}, [intervalMs, router]);
return null;
}