fix(webui): the live stream reopens after a fatal close; quieter connection status
A non-200 answer to /api/stream (the backend restarting behind a proxy) closes an EventSource for good, so the top bar read Disconnected until a reload while every fetch worked. The live-updates store now reopens it after 1s, doubling to a 30s cap, and resets once live. The connection status becomes a dot and a label, coloured only when not connected. History drops the edge fade, which washed out its first and last columns though nothing overflowed, and its section filter names the section rather than showing the raw kind.
This commit is contained in:
7 files changed
+55
-28
No files matched your search
@@ -2,25 +2,21 @@
|
||||
import { computed } from "vue";
|
||||
import { storeToRefs } from "pinia";
|
||||
|
||||
import { StatusPill } from "@/components/ui/status-pill";
|
||||
import { connectionStatus } from "@/lib/connection";
|
||||
import { useLiveUpdatesStore } from "@/stores/live-updates";
|
||||
|
||||
const { streamState } = storeToRefs(useLiveUpdatesStore());
|
||||
const status = computed(() => connectionStatus(streamState.value));
|
||||
const pill = {
|
||||
ok: { tone: "neutral", dot: "live" },
|
||||
warn: { tone: "warn", dot: "warn" },
|
||||
danger: { tone: "danger", dot: "danger" },
|
||||
const look = {
|
||||
ok: { dot: "bg-primary", text: "text-fg-subtle" },
|
||||
warn: { dot: "bg-warn", text: "text-warn" },
|
||||
danger: { dot: "bg-danger", text: "text-danger" },
|
||||
} as const;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<StatusPill
|
||||
:tone="pill[status.tone].tone"
|
||||
:dot="pill[status.tone].dot"
|
||||
role="status"
|
||||
class="max-sm:hidden"
|
||||
>{{ status.label }}</StatusPill
|
||||
>
|
||||
<span role="status" class="inline-flex items-center gap-1.5 px-1 text-xs max-sm:hidden" :class="look[status.tone].text">
|
||||
<span class="size-1.5 rounded-full" :class="look[status.tone].dot" aria-hidden="true" />
|
||||
{{ status.label }}
|
||||
</span>
|
||||
</template>
|
||||
@@ -22,3 +22,12 @@ export function streamStateFor(readyState: number): StreamState {
|
||||
if (readyState === 1) return "live";
|
||||
return "unavailable";
|
||||
}
|
||||
|
||||
/**
|
||||
* reconnectDelay is how long to wait before re-opening a stream the browser
|
||||
* gave up on (a non-200 answer closes an EventSource for good): doubling from
|
||||
* one second, capped at thirty.
|
||||
*/
|
||||
export function reconnectDelay(attempt: number): number {
|
||||
return Math.min(1000 * 2 ** attempt, 30_000);
|
||||
}
|
||||
@@ -107,7 +107,9 @@ async function restoreBefore(entry: AuditEntry): Promise<void> {
|
||||
|
||||
<div class="mb-4 flex flex-wrap gap-2">
|
||||
<Select v-model="section">
|
||||
<SelectTrigger class="w-60" aria-label="Section"><SelectValue /></SelectTrigger>
|
||||
<SelectTrigger class="w-60" aria-label="Section">
|
||||
<SelectValue>{{ section === ALL ? "All sections" : sectionOptions.find((o) => o.value === section)?.label ?? section }}</SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem :value="ALL">All sections</SelectItem>
|
||||
<SelectItem v-for="o in sectionOptions" :key="o.value" :value="o.value">{{ o.label }}</SelectItem>
|
||||
@@ -132,7 +134,7 @@ async function restoreBefore(entry: AuditEntry): Promise<void> {
|
||||
</div>
|
||||
|
||||
<p v-if="error" class="text-sm text-danger" role="alert">{{ error }}</p>
|
||||
<div v-else class="scroll-fade-x overflow-x-auto rounded-lg border border-border bg-card [scrollbar-width:none]">
|
||||
<div v-else class="overflow-x-auto rounded-lg border border-border bg-card">
|
||||
<table class="w-full text-[13px]">
|
||||
<thead>
|
||||
<tr class="border-b border-border text-left text-[11px] tracking-[0.06em] text-fg-subtle uppercase">
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
|
||||
import { setAuthenticationStateHandler, subscribeEvents, type StreamFrame } from "../lib/api.ts";
|
||||
import type { StatusKind } from "@/lib/status";
|
||||
import type { StreamState } from "@/lib/stream-state";
|
||||
import { reconnectDelay, type StreamState } from "../lib/stream-state.ts";
|
||||
import {
|
||||
resourcesForEvent,
|
||||
type LiveEvent,
|
||||
@@ -51,12 +51,24 @@ export const useLiveUpdatesStore = defineStore("live-updates", () => {
|
||||
for (const listener of listeners.get(frame.topic) ?? []) listener(frame.data);
|
||||
}
|
||||
|
||||
// The browser retries a dropped stream itself, but a non-200 answer (the
|
||||
// backend restarting behind a proxy) closes it for good; reopen it then, or
|
||||
// the page reads "Disconnected" until a reload.
|
||||
let retryTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
let retryAttempt = 0;
|
||||
|
||||
function connect(): void {
|
||||
clearTimeout(retryTimer);
|
||||
unsubscribe?.();
|
||||
streamState.value = "connecting";
|
||||
unsubscribe = subscribeEvents(handleFrame, (state) => {
|
||||
streamState.value = state;
|
||||
if (state === "live") connectionRevision.value += 1;
|
||||
if (state === "live") {
|
||||
retryAttempt = 0;
|
||||
connectionRevision.value += 1;
|
||||
} else if (state === "unavailable") {
|
||||
retryTimer = setTimeout(connect, reconnectDelay(retryAttempt++));
|
||||
}
|
||||
}, cursor, logsReaders > 0);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user