From 434bd0004ab4cc6258c31559535b4c89d92fcbb6 Mon Sep 17 00:00:00 2001 From: mc-nekoneko Date: Fri, 6 Mar 2026 19:17:57 +0900 Subject: [PATCH] fix: send full history to fresh SSE connections Previously, history replay only triggered on reconnection with a Last-Event-ID header. New connections (e.g. dashboard initial load) received no history, so recent events were invisible until a new event was fired. Now, fresh connections without Last-Event-ID receive the full stored history on connect, so dashboards show recent activity immediately. --- src/channel.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/channel.ts b/src/channel.ts index 19346c6..ddc4524 100644 --- a/src/channel.ts +++ b/src/channel.ts @@ -50,12 +50,16 @@ export class Channel extends DurableObject { const writer = writable.getWriter(); this.connections.add(writer); - // Send missed events (Last-Event-ID replay) - if (lastEventId) { - const idx = this.history.findIndex((e) => e.id === lastEventId); - const missed = idx >= 0 ? this.history.slice(idx + 1) : this.history; + // Send history: replay missed events on reconnect, or full history on fresh connect + const toReplay = lastEventId + ? (() => { + const idx = this.history.findIndex((e) => e.id === lastEventId); + return idx >= 0 ? this.history.slice(idx + 1) : this.history; + })() + : this.history.slice(); // fresh connection → send full history + if (toReplay.length > 0) { (async () => { - for (const ev of missed) { + for (const ev of toReplay) { await writer.write(this.encoder.encode(this.format(ev))); } })();