From 9e56737f3f7d3e74622da5cb279b5ab71fbe3e25 Mon Sep 17 00:00:00 2001 From: stevenjj33 <75509501+stevenjj33@users.noreply.github.com> Date: Mon, 9 Nov 2026 23:56:34 +0800 Subject: [PATCH 1/2] fix(webui): clicking the selected session's rail link returns to the conversation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A rail session row is a plain `#session=` anchor, so the selection runs through the hash subscription rather than through a setter the shell holds. Clicking the link of the session that is already selected changes nothing that subscription can observe -- the hash is the same, so no `hashchange` fires and the effect that puts the conversation back does not run again. The shell stayed on the 远程 page although the user asked for the conversation. The click is the one signal left, so the shell listens for it on the rail's session links in the capture phase and puts the conversation back. --- .../client/shell/WebuiClientFoundationApp.tsx | 20 ++++++++ .../browser/rail-session-navigation.spec.mjs | 51 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 packages/webui/test/browser/rail-session-navigation.spec.mjs diff --git a/packages/webui/src/client/shell/WebuiClientFoundationApp.tsx b/packages/webui/src/client/shell/WebuiClientFoundationApp.tsx index 222161d79..a2d947fba 100644 --- a/packages/webui/src/client/shell/WebuiClientFoundationApp.tsx +++ b/packages/webui/src/client/shell/WebuiClientFoundationApp.tsx @@ -386,6 +386,26 @@ export function WebuiClientFoundationApp( useEffect(() => { dispatchShellSurface({ type: "show-conversation" }); }, [dispatchShellSurface, selectedSessionId]); + // Clicking the rail link of the session that is already selected changes + // nothing the hash subscription can observe: the hash is the same, so no + // `hashchange` fires, the selection does not change, and the effect above + // does not run again -- the shell keeps the surface it was showing (the + // marketplace, the 远程 page) although the user asked for the conversation. + // The click is the one signal left, so the shell listens for it on the rail's + // session links and puts the conversation back. + useEffect(() => { + if (!selectedSessionId) return; + const onSessionLinkClick = (event: MouseEvent) => { + const target = event.target; + if (!(target instanceof Element)) return; + const link = target.closest("[data-webui-session-link]"); + if (!link) return; + if (link.getAttribute("data-webui-session-link") !== selectedSessionId) return; + dispatchShellSurface({ type: "show-conversation" }); + }; + document.addEventListener("click", onSessionLinkClick, true); + return () => document.removeEventListener("click", onSessionLinkClick, true); + }, [dispatchShellSurface, selectedSessionId]); // Composer input history + per-session drafts. The one owner is the application // composer store: the shell subscribes to it and submits through it. const composerState = useSyncExternalStore( diff --git a/packages/webui/test/browser/rail-session-navigation.spec.mjs b/packages/webui/test/browser/rail-session-navigation.spec.mjs new file mode 100644 index 000000000..30d92604d --- /dev/null +++ b/packages/webui/test/browser/rail-session-navigation.spec.mjs @@ -0,0 +1,51 @@ +// The rail's session links, end to end against the built client. +// +// A rail session row is a plain `#session=` anchor, so selecting a session +// runs through the hash subscription inside `useSelectedSessionId` rather than +// through a setter the shell holds. Clicking the link of the session that is +// *already* selected changes nothing that subscription can observe: the hash +// stays the same, so no `hashchange` fires, the selection does not change, and +// the shell never hears that the user asked for the conversation -- it keeps +// the surface it was showing. +// +// The symptom is the 远程 page: open it, click the session you are already in, +// and the page stays put. +// +// The session link is clicked by dispatching the event rather than by moving +// the pointer. The rail row carries its own action buttons (置顶, 归档, 更多) on +// the right, and they intercept the pointer at the link's centre -- the same +// spot a user has to aim around. + +import { expect } from "@playwright/test"; + +import { openApp, test } from "./harness.mjs"; + +function sessionLink(page, sessionId) { + return page.locator(`[data-webui-session-link="${sessionId}"]`); +} + +function conversation(page) { + return page.locator('[data-webui-session-layout="true"]'); +} + +function remotePage(page) { + return page.locator('[data-webui-component="remote-page"]'); +} + +test("clicking the selected session's rail link returns to the conversation", async ({ page }) => { + await openApp(page, "#session=A"); + + await expect(sessionLink(page, "A")).toBeVisible(); + await expect(conversation(page)).toBeVisible(); + + await page.locator('[data-webui-nav-item="远程"]').click(); + await expect(remotePage(page)).toBeVisible(); + await expect(conversation(page)).toHaveCount(0); + + // The same session, clicked again. The hash does not change, so this click + // is the only signal the shell gets. + await sessionLink(page, "A").dispatchEvent("click"); + + await expect(remotePage(page)).toHaveCount(0); + await expect(conversation(page)).toBeVisible(); +}); From 415e4bb1da0ec964fc64e9d18437677e87725615 Mon Sep 17 00:00:00 2001 From: stevenjj33 <75509501+stevenjj33@users.noreply.github.com> Date: Tue, 10 Nov 2026 00:16:32 +0800 Subject: [PATCH 2/2] fix(webui): reach the click through the platform's DOM capability The shell may not touch the document: `document`, `localStorage` and `sessionStorage` are the restricted ambient members, and the dependency check says so. The listener belongs to the platform's DOM capability, which already carries the document's listeners, so `listenForClick` joins them and the shell subscribes to the capability it already holds. The behaviour is the same document listener in the capture phase. --- packages/webui/src/client/platform/browser-dom.ts | 9 +++++++++ .../webui/src/client/shell/WebuiClientFoundationApp.tsx | 8 +++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/webui/src/client/platform/browser-dom.ts b/packages/webui/src/client/platform/browser-dom.ts index d741be11c..45f729638 100644 --- a/packages/webui/src/client/platform/browser-dom.ts +++ b/packages/webui/src/client/platform/browser-dom.ts @@ -95,6 +95,14 @@ export interface WebuiBrowserDom { readonly portalTarget: () => HTMLElement | null; readonly listenForMouseDown: (listener: (event: MouseEvent) => void) => () => void; readonly listenForPointerDown: (listener: (event: PointerEvent) => void, capture?: boolean) => () => void; + /** + * A click anywhere in the document. + * + * A rail row is a plain anchor, so the surface that owns the shell hears + * the clicks the row cannot report itself. The listener is the document's, + * and it is the platform's: a surface does not reach for the document. + */ + readonly listenForClick: (listener: (event: MouseEvent) => void, capture?: boolean) => () => void; readonly listenForKeyDown: (listener: (event: KeyboardEvent) => void) => () => void; /** * The viewport was resized. @@ -241,6 +249,7 @@ export function createWebuiBrowserDom( portalTarget: () => documentObject?.body ?? null, listenForMouseDown: (listener) => listen("mousedown", listener), listenForPointerDown: (listener, capture) => listen("pointerdown", listener, capture), + listenForClick: (listener, capture) => listen("click", listener, capture), listenForKeyDown: (listener) => listen("keydown", listener), listenForResize: (listener) => { if (!windowObject) return () => undefined; diff --git a/packages/webui/src/client/shell/WebuiClientFoundationApp.tsx b/packages/webui/src/client/shell/WebuiClientFoundationApp.tsx index a2d947fba..a29e94831 100644 --- a/packages/webui/src/client/shell/WebuiClientFoundationApp.tsx +++ b/packages/webui/src/client/shell/WebuiClientFoundationApp.tsx @@ -395,17 +395,15 @@ export function WebuiClientFoundationApp( // session links and puts the conversation back. useEffect(() => { if (!selectedSessionId) return; - const onSessionLinkClick = (event: MouseEvent) => { + return browserDom.listenForClick((event) => { const target = event.target; if (!(target instanceof Element)) return; const link = target.closest("[data-webui-session-link]"); if (!link) return; if (link.getAttribute("data-webui-session-link") !== selectedSessionId) return; dispatchShellSurface({ type: "show-conversation" }); - }; - document.addEventListener("click", onSessionLinkClick, true); - return () => document.removeEventListener("click", onSessionLinkClick, true); - }, [dispatchShellSurface, selectedSessionId]); + }, true); + }, [browserDom, dispatchShellSurface, selectedSessionId]); // Composer input history + per-session drafts. The one owner is the application // composer store: the shell subscribes to it and submits through it. const composerState = useSyncExternalStore(