web: keep chat stable while streaming and refresh Settings

Preserve scroll intent for touch scrolling, coalesce live frames into one paint,
keep stable dialogs mounted across re-renders, and add a Settings refresh that
pings the server for a fresh build/time card.
This commit is contained in:
2026-10-20 03:35:45 +01:00
parent d5cda887ee
commit 4072698731
5 changed files with 82 additions and 4 deletions
+28 -3
View File
@@ -628,6 +628,25 @@ function settleChatThreads() {
* ignored); the server only pushes frames for sessions this connection subscribed
* to, so this is a no-op in practice until a chat is opened.
*/
let chatRenderScheduled = false;
/**
* Coalesce a burst of pushed frames into one paint. A turn can emit many text
* and tool frames in the same animation frame; rebuilding the transcript for
* each one made the text flicker and restarted in-flight animations. State is
* folded immediately; only the DOM paint is deferred.
*/
function scheduleChatRender() {
if (chatRenderScheduled) return;
chatRenderScheduled = true;
const paint = () => {
chatRenderScheduled = false;
renderContent();
};
if (typeof requestAnimationFrame === "function") requestAnimationFrame(paint);
else setTimeout(paint, 0);
}
function onChatEvent(frame) {
const sessionId = String(frame?.session_id ?? "").trim();
if (!sessionId || !state.chatThreads.has(sessionId)) return;
@@ -641,7 +660,7 @@ function onChatEvent(frame) {
// missed) appears without a manual refresh.
const knownTurn = messageId !== "" && (thread.messages ?? []).some((m) => m?.id === messageId);
state.chatThreads.set(sessionId, applyChatEvent(thread, frame, Date.now()));
renderContent();
scheduleChatRender();
if (!knownTurn) scheduleHistorySync(sessionId, messageId);
}
@@ -693,7 +712,7 @@ function onChatPermission(frame) {
next.permissionError = "";
}
state.chatThreads.set(sessionId, next);
if (sessionId === state.chatActiveId) renderContent();
if (sessionId === state.chatActiveId) scheduleChatRender();
}
/**
@@ -1175,7 +1194,7 @@ function onChatFrame(message) {
const running = runningAfterFrame(thread.running, frame);
if (queued === thread.queued && running === thread.running) return;
setThread(sessionId, { queued, running });
if (sessionId === state.chatActiveId) renderContent();
if (sessionId === state.chatActiveId) scheduleChatRender();
}
/** Add one local command line to a conversation's transcript. */
@@ -2125,6 +2144,7 @@ function renderChatRenameDialog(session) {
role: "dialog",
"aria-modal": "true",
"aria-label": CHAT_RENAME_TITLE,
"data-modal-stable": "true",
});
overlay.addEventListener("click", (event) => {
if (event.target === overlay) dismissChatRename();
@@ -3336,6 +3356,7 @@ function renderChatCloseDialog(session) {
role: "dialog",
"aria-modal": "true",
"aria-label": CLOSE_CHAT_TITLE,
"data-modal-stable": "true",
});
overlay.addEventListener("click", (event) => {
if (event.target === overlay) dismissChatClose();
@@ -3444,6 +3465,10 @@ function afterChatRender() {
// scrolls therefore leaves the intent alone.
let gesture = false;
const beginGesture = () => {
// A touch/pointer scroll is the operator's own intent, exactly like a wheel.
// Without this, a phone scroll up never cleared `chatFollowing`, so the next
// streamed frame snapped the transcript back to the bottom.
state.chatUserIntent = true;
gesture = true;
};
const endGesture = () => {