From 09a007937f03fad04a390323f3817f1ae7d7c2a9 Mon Sep 17 00:00:00 2001 From: Christophe Besson Date: Fri, 28 Aug 2026 17:54:43 +0200 Subject: fix(transport): chat_hist_resp dispatch skipped when older pending entries exist chat_hist_resp checked only the single oldest pending entry across all types. When switching tabs, keyed requests (media_meta_req, file_req) from Videos/Music/Photos stayed in _pending and were older than the chat_hist entry, so the response was dropped and the chat appeared empty on return. Now scans for the first chat_hist entry instead. Same fix applied to index_sync dispatch for consistency. Co-Authored-By: Claude Opus 4.6 --- .../meshbay-hub/src/meshbay_hub/static/transport.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/meshbay-hub/src/meshbay_hub/static/transport.js b/packages/meshbay-hub/src/meshbay_hub/static/transport.js index 1a146ce..120c7d7 100644 --- a/packages/meshbay-hub/src/meshbay_hub/static/transport.js +++ b/packages/meshbay-hub/src/meshbay_hub/static/transport.js @@ -2121,9 +2121,11 @@ class MeshBayTransport { if (msg.type === 'index_sync' && msg.entries) { if (this._onIndexSync) this._onIndexSync(msg); - const oldest = this._pending.entries().next(); - if (!oldest.done && oldest.value[1]._reqType === 'index_sync') { - oldest.value[1].resolve(msg); + for (const [, handler] of this._pending) { + if (handler._reqType === 'index_sync') { + handler.resolve(msg); + break; + } } return; } @@ -2251,12 +2253,13 @@ class MeshBayTransport { // what depending on response arrival order rather than on request type // predicts: it fires only when the two responses happen to reorder. if (msg.type === 'chat_hist_resp') { - const oldest = this._pending.entries().next(); - if (!oldest.done && oldest.value[1]._reqType === 'chat_hist') { - oldest.value[1].resolve(msg); - } else { - console.warn('[MeshBay] chat_hist_resp with no matching chat_hist pending'); + for (const [, handler] of this._pending) { + if (handler._reqType === 'chat_hist') { + handler.resolve(msg); + return; + } } + console.warn('[MeshBay] chat_hist_resp with no matching chat_hist pending'); return; } -- cgit v1.2.3