From d862d953e1a64134c99f395e1e9ce98c46d213c8 Mon Sep 17 00:00:00 2001 From: Stan Grams Date: Tue, 10 Mar 2026 19:40:08 +0100 Subject: [PATCH] [fix](trx-frontend-http): flush live decode buffer only after history drain completes drainDecodeHistory() chunks work via setTimeout but flushLiveBuffer() was called synchronously right after starting the drain, so live messages could interleave with in-progress history chunks. Pass flushLiveBuffer as an onDone callback so live messages are only dispatched once all history chunks have been processed. Co-Authored-By: Claude Sonnet 4.6 Signed-off-by: Stan Grams --- .../trx-frontend-http/assets/web/app.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/trx-client/trx-frontend/trx-frontend-http/assets/web/app.js b/src/trx-client/trx-frontend/trx-frontend-http/assets/web/app.js index a85071a..8e8ba35 100644 --- a/src/trx-client/trx-frontend/trx-frontend-http/assets/web/app.js +++ b/src/trx-client/trx-frontend/trx-frontend-http/assets/web/app.js @@ -6162,11 +6162,15 @@ function dispatchDecodeMessage(msg) { if (msg.type === "wspr" && window.onServerWspr) window.onServerWspr(msg); } -function drainDecodeHistory(buffer, index) { +function drainDecodeHistory(buffer, index, onDone) { const CHUNK = 30; const end = Math.min(index + CHUNK, buffer.length); for (let i = index; i < end; i++) dispatchDecodeMessage(buffer[i]); - if (end < buffer.length) setTimeout(() => drainDecodeHistory(buffer, end), 0); + if (end < buffer.length) { + setTimeout(() => drainDecodeHistory(buffer, end, onDone), 0); + } else if (typeof onDone === "function") { + onDone(); + } } function connectDecode() { @@ -6224,8 +6228,11 @@ function connectDecode() { return resp.json(); }).then((msgs) => { clearTimeout(historyTimeout); - if (Array.isArray(msgs)) drainDecodeHistory(msgs, 0); - flushLiveBuffer(); + if (Array.isArray(msgs) && msgs.length > 0) { + drainDecodeHistory(msgs, 0, flushLiveBuffer); + } else { + flushLiveBuffer(); + } }).catch(() => { clearTimeout(historyTimeout); flushLiveBuffer(); }); } if (document.readyState === "complete") {