'use client'; import { useEffect, useMemo, useState } from 'react'; import { RefreshCw, X } from 'lucide-react'; import { api } from '@/lib/api'; import { getClientRuntimeVersion, shouldPromptForNewRuntimeVersion, type ServerRuntimeVersion, } from '@/lib/runtime-version'; const VERSION_POLL_MS = 60_000; export function RuntimeVersionBanner() { const clientVersion = useMemo(() => getClientRuntimeVersion(), []); const [serverVersion, setServerVersion] = useState(null); const [dismissedVersion, setDismissedVersion] = useState(''); useEffect(() => { let cancelled = false; let timer: ReturnType | undefined; const load = async () => { try { const next = await api.get('/health/version'); if (!cancelled) setServerVersion(next); } catch { if (!cancelled) setServerVersion(null); } }; void load(); timer = setInterval(() => void load(), VERSION_POLL_MS); return () => { cancelled = true; if (timer) clearInterval(timer); }; }, []); const shouldShow = serverVersion && serverVersion.version !== dismissedVersion && shouldPromptForNewRuntimeVersion(clientVersion.version, serverVersion.version); if (!shouldShow || !serverVersion) return null; return (

发现新版本

服务器已更新到 {serverVersion.version.slice(0, 7)},刷新后可使用最新前端。

); }