web: keep mobile composition stable across keyboard and Back navigation

This commit is contained in:
2026-10-20 16:04:09 +01:00
parent 90cd43bdd7
commit 1d9cb80cdb
9 changed files with 193 additions and 10 deletions
+17 -6
View File
@@ -67,6 +67,7 @@ import {
readEphemeralChatIds,
} from "./views/chat.js";
import { createSearchView } from "./views/search.js";
import { installMobileViewport } from "./mobileViewport.js";
function defaultServerUrl() {
if (typeof location === "undefined" || !location.host) return "";
@@ -76,6 +77,7 @@ function defaultServerUrl() {
const client = new PipelinesClient();
const repo = new PipelinesRepository(client);
installMobileViewport();
// Register the app's shell service worker where the browser allows it (a secure
// context: https, localhost, or the desktop app). On a plain-LAN http origin the
@@ -1035,7 +1037,7 @@ function restoreListFocus(restore) {
// first focusable descendant rather than a non-focusable div.
const target =
row.matches("button, a, [tabindex]") ? row : row.querySelector("button, a, [tabindex]") ?? row;
target.focus();
target.focus({ preventScroll: true });
return;
}
}
@@ -1107,7 +1109,14 @@ function render() {
renderAttentionSheet();
}
const listScrollPositions = new Map();
function renderContent() {
const previousList = content.querySelector(".list-pane");
const previousScroll = previousList?.querySelector(".list-scroll");
if (previousScroll && previousList.getClientRects().length > 0) {
listScrollPositions.set(previousList.dataset.listView, previousScroll.scrollTop);
}
// The graph owns wheel/pointer/resize listeners; drop the previous mount
// before rebuilding the DOM so a re-render, tab switch or view switch never
// leaves an observer or listener behind.
@@ -1159,7 +1168,7 @@ function renderContent() {
layout.append(
h(
"section",
{ class: "list-pane", "aria-label": "Pipelines list" },
{ class: "list-pane", "data-list-view": view, "aria-label": "Pipelines list" },
paneHeading("Pipelines", { detailOpen }),
renderPipelineList(),
),
@@ -1169,7 +1178,7 @@ function renderContent() {
layout.append(
h(
"section",
{ class: "list-pane", "aria-label": "Runs list" },
{ class: "list-pane", "data-list-view": view, "aria-label": "Runs list" },
paneHeading("Runs", { detailOpen }),
renderRunList(),
),
@@ -1179,7 +1188,7 @@ function renderContent() {
layout.append(
h(
"section",
{ class: "list-pane", "aria-label": "Templates list" },
{ class: "list-pane", "data-list-view": view, "aria-label": "Templates list" },
paneHeading("Templates", { detailOpen }),
renderTemplateGallery(),
),
@@ -1189,7 +1198,7 @@ function renderContent() {
layout.append(
h(
"section",
{ class: "list-pane", "aria-label": "Chat list" },
{ class: "list-pane", "data-list-view": view, "aria-label": "Chat list" },
paneHeading("Chat", { detailOpen }),
renderChatList(),
),
@@ -1222,6 +1231,8 @@ function renderContent() {
}
}
content.replaceChildren(...nodes);
const restoredList = content.querySelector(".list-pane .list-scroll");
if (restoredList) restoredList.scrollTop = listScrollPositions.get(state.view) ?? 0;
if (!reduceMotion) {
for (const node of content.querySelectorAll("[data-animate-key]")) {
const key = node.getAttribute("data-animate-key");
@@ -2659,4 +2670,4 @@ if (bootServerUrl) {
state.url = sameOrigin;
openConfiguredEndpoint({ surfaceError: false });
}
}
}