From c49a5a0aa8753d06a7fc81739034a39a833e51b3 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Tue, 7 Jul 2026 22:17:16 +0800 Subject: [PATCH] perf(webui): make debug feed pause truly close the SSE (#185) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The live-activity feed kept its /api/debug/stream EventSource open while paused and merely dropped frames in the handler, so a paused feed still held a backend connection slot and processed every event for nothing. Make `paused` a dependency of the subscription effect: pausing now closes the stream and resuming reopens it. Events during a pause were already discarded, and the row buffer is preserved across toggles, so the only change is that a paused feed stops consuming. Deliberately NOT gated on tab visibility: debug-page keeps this component mounted across tabs on purpose (the comment there notes actions fired from other tabs must still land in the feed), so closing on tab switch would regress that. Only an explicit pause severs the connection. StatusPill gained a `paused` state so a deliberate pause reads as 已暂停 rather than 未连接. --- .../src/components/debug/live-activity.tsx | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/packages/webui/src/components/debug/live-activity.tsx b/packages/webui/src/components/debug/live-activity.tsx index 4ab93647..632dc3f4 100644 --- a/packages/webui/src/components/debug/live-activity.tsx +++ b/packages/webui/src/components/debug/live-activity.tsx @@ -25,12 +25,15 @@ function IconBtn({ onClick, title, children }: { onClick: () => void; title: str ); } -function StatusPill({ status }: { status: 'open' | 'reconnecting' | 'closed' }) { - const map = { - open: { dot: 'bg-emerald-500', label: '已连接', glow: 'shadow-[0_0_0_3px_rgb(16_185_129/0.15)]' }, - reconnecting: { dot: 'bg-amber-500', label: '重连中', glow: 'shadow-[0_0_0_3px_rgb(245_158_11/0.15)]' }, - closed: { dot: 'bg-muted-foreground/50', label: '未连接', glow: '' }, - }[status]; +function StatusPill({ status, paused }: { status: 'open' | 'reconnecting' | 'closed'; paused?: boolean }) { + // A deliberate pause reads as "已暂停", distinct from an unwanted disconnect. + const map = paused + ? { dot: 'bg-muted-foreground/50', label: '已暂停', glow: '' } + : { + open: { dot: 'bg-emerald-500', label: '已连接', glow: 'shadow-[0_0_0_3px_rgb(16_185_129/0.15)]' }, + reconnecting: { dot: 'bg-amber-500', label: '重连中', glow: 'shadow-[0_0_0_3px_rgb(245_158_11/0.15)]' }, + closed: { dot: 'bg-muted-foreground/50', label: '未连接', glow: '' }, + }[status]; return (
@@ -94,14 +97,18 @@ export function LiveActivity() { const [status, setStatus] = useState<'open' | 'reconnecting' | 'closed'>('closed'); const [kindFilter, setKindFilter] = useState<'all' | 'event' | 'action'>('all'); const [query, setQuery] = useState(''); - const pausedRef = useRef(paused); - useEffect(() => { pausedRef.current = paused; }, [paused]); const idRef = useRef(0); + // Pausing truly drops the EventSource instead of connecting-and-discarding: + // `paused` is an effect dependency, so it closes the stream on pause and + // reopens it on resume. (The always-on-across-tabs behaviour is intentional — + // debug-page keeps this mounted so actions fired from other tabs still land in + // the feed — so only an explicit pause severs the connection.) useEffect(() => { + if (paused) return; const off = api.debug.stream( (m) => { - if (m.kind === 'ready' || pausedRef.current) return; + if (m.kind === 'ready') return; setRows((prev) => { // Precompute the search haystack once at enqueue, so filtering never // re-stringifies every row on each keystroke. @@ -112,7 +119,7 @@ export function LiveActivity() { (s) => setStatus(s), ); return off; - }, [api]); + }, [paused, api]); const visible = useMemo(() => { const q = query.trim().toLowerCase(); @@ -149,7 +156,7 @@ export function LiveActivity() {

实时活动

{visible.length} - +