fix: preserve log message order when replaying history on connect

Send history messages newest-first from the server, tagged with
history=True so the client appends rather than prepends them, avoiding
reverse-chronological display on initial load.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Andreas Wrede
2026-05-21 11:18:05 -04:00
parent c47576637f
commit f4231dd5f3
2 changed files with 6 additions and 4 deletions
+1 -1
View File
@@ -540,7 +540,7 @@
if (msg.service) html += '<span class="log-service">' + msg.service + '</span>'; if (msg.service) html += '<span class="log-service">' + msg.service + '</span>';
html += '<span class="log-msg">' + msg.message + '</span>'; html += '<span class="log-msg">' + msg.message + '</span>';
html += '</div>'; html += '</div>';
msgs.insertAdjacentHTML("afterbegin", html); msgs.insertAdjacentHTML(state.history ? "beforeend" : "afterbegin", html);
applyLogFilters(); applyLogFilters();
} }
cnt++; cnt++;
+5 -3
View File
@@ -85,13 +85,15 @@ async def handler(request):
except Exception as e: except Exception as e:
logger.error("Error sending initial hosts: %s", e) logger.error("Error sending initial hosts: %s", e)
# Send recent messages, filtered to hosts this user may see # Send recent messages newest-first so the client can append them in
# display order without reordering on arrival (tagged history=True so
# the client knows to append rather than prepend).
if data.msgs: if data.msgs:
try: try:
for m in data.msgs: for m in reversed(data.msgs):
host_name = m.get("host") if isinstance(m, dict) else None host_name = m.get("host") if isinstance(m, dict) else None
if not host_name or _user_can_see_host(user, host_name): if not host_name or _user_can_see_host(user, host_name):
await ws.send_str(json.dumps({"type": "message", "data": m})) await ws.send_str(json.dumps({"type": "message", "data": m, "history": True}))
except Exception as e: except Exception as e:
logger.error("Error sending initial messages: %s", e) logger.error("Error sending initial messages: %s", e)