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:
@@ -389,6 +389,16 @@ export function createModalController(options = {}) {
|
||||
entry.options = { ...entry.options, ...staged.options };
|
||||
if (entry.trigger == null && staged.trigger) entry.trigger = staged.trigger;
|
||||
if (entry.panel === staged.panel) return false;
|
||||
// A stable dialog keeps its mounted panel across streaming re-renders. A
|
||||
// rebuild would restart the modal-in animation (the rename dialog visibly
|
||||
// blinked/reappeared on every chat frame) and discard whatever the operator
|
||||
// had typed into it.
|
||||
if (
|
||||
entry.panel?.getAttribute?.("data-modal-stable") === "true" &&
|
||||
staged.panel?.getAttribute?.("data-modal-stable") === "true"
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
const remembered = rememberFocus(entry.panel);
|
||||
const oldPanel = entry.panel;
|
||||
if (typeof oldPanel.replaceWith === "function" && oldPanel.parentElement) {
|
||||
|
||||
+28
-3
@@ -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 = () => {
|
||||
|
||||
@@ -49,7 +49,18 @@ export function createSettingsView(rt) {
|
||||
function renderSettingsView() {
|
||||
const pane = h("div", { class: "settings" });
|
||||
pane.append(
|
||||
h("h1", { class: "settings-page-title", id: "detailTitle", tabindex: "-1", text: "Settings" }),
|
||||
h(
|
||||
"div",
|
||||
{ class: "settings-head" },
|
||||
h("h1", { class: "settings-page-title", id: "detailTitle", tabindex: "-1", text: "Settings" }),
|
||||
h("button", {
|
||||
id: "settingsRefresh",
|
||||
class: "ghost settings-refresh",
|
||||
type: "button",
|
||||
text: "Refresh",
|
||||
onclick: () => refreshSettingsStatus(),
|
||||
}),
|
||||
),
|
||||
renderSettingsConnection(),
|
||||
renderSettingsWorkspace(),
|
||||
renderSettingsNotifications(),
|
||||
@@ -261,6 +272,27 @@ function serverUrlSupportingText() {
|
||||
* aria-invalid and the error tint) so an invalid Connect never needs a full
|
||||
* re-render and the field being typed in is never rebuilt.
|
||||
*/
|
||||
/**
|
||||
* Refresh the Settings page's live server facts. The page has no list to reload
|
||||
* (its fields are local and its cards derive from the connection), so this sends
|
||||
* the same ping the first connection uses and repaints the status card with the
|
||||
* server's current build/time. It never reconnects or mutates a setting.
|
||||
*/
|
||||
async function refreshSettingsStatus() {
|
||||
if (state.connection.kind === "connected") {
|
||||
try {
|
||||
const reply = await repo.ping();
|
||||
state.serverProtocol = reply?.protocol ?? null;
|
||||
state.serverBuild = reply?.build ?? null;
|
||||
state.serverTime = reply?.time ?? null;
|
||||
} catch {
|
||||
// The connection card already carries the honest socket state; a ping
|
||||
// failure must not replace it with a second, stale error line.
|
||||
}
|
||||
}
|
||||
renderContent();
|
||||
}
|
||||
|
||||
function refreshServerUrlError() {
|
||||
const field = document.getElementById("settingsServerUrl");
|
||||
const helper = document.getElementById("settingsUrlHelper");
|
||||
|
||||
Reference in New Issue
Block a user