Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/webui/src/client/platform/browser-dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions packages/webui/src/client/shell/WebuiClientFoundationApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,24 @@ 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;
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" });
}, 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(
Expand Down
51 changes: 51 additions & 0 deletions packages/webui/test/browser/rail-session-navigation.spec.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// The rail's session links, end to end against the built client.
//
// A rail session row is a plain `#session=<id>` 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();
});
Loading