Skip to content

Commit 2ebe24e

Browse files
authored
fix(ui): keep sidebar chat rows separated during resize (#126610)
1 parent 2c435f7 commit 2ebe24e

5 files changed

Lines changed: 190 additions & 1 deletion

File tree

‎ui/src/e2e/board-split-transcript.e2e.test.ts‎

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ let browser: Browser;
2626
let controlUi: ControlUiE2eServer;
2727
const contexts = new Set<BrowserContext>();
2828

29+
type TranscriptGeometry = {
30+
width: number;
31+
rowGap: number;
32+
assistantUserGap: number;
33+
};
34+
2935
function boardSnapshot(chatDock: "right" | "hidden", revision = 1) {
3036
return {
3137
sessionKey,
@@ -58,6 +64,43 @@ async function visibleTranscriptState(page: Page) {
5864
});
5965
}
6066

67+
async function firstSidebarResizeFrame(page: Page, resize: () => Promise<void>) {
68+
const firstFrame = page.evaluate(
69+
() =>
70+
new Promise<TranscriptGeometry>((resolve, reject) => {
71+
const panel = document.querySelector<HTMLElement>(".side-panel");
72+
if (!panel) {
73+
throw new Error("Board chat side panel is missing");
74+
}
75+
const observer = new MutationObserver(() => {
76+
observer.disconnect();
77+
requestAnimationFrame(() => {
78+
const [assistantRow, userRow] =
79+
panel.querySelectorAll<HTMLElement>(".chat-virtual-row");
80+
const assistant = assistantRow?.querySelector<HTMLElement>(
81+
".chat-group.assistant .chat-text",
82+
);
83+
const user = userRow?.querySelector<HTMLElement>(".chat-group.user .chat-bubble");
84+
if (!assistantRow || !userRow || !assistant || !user) {
85+
reject(new Error("Adjacent assistant and user transcript rows are missing"));
86+
return;
87+
}
88+
resolve({
89+
width: panel.getBoundingClientRect().width,
90+
rowGap:
91+
userRow.getBoundingClientRect().top - assistantRow.getBoundingClientRect().bottom,
92+
assistantUserGap:
93+
user.getBoundingClientRect().top - assistant.getBoundingClientRect().bottom,
94+
});
95+
});
96+
});
97+
observer.observe(panel, { attributes: true, attributeFilter: ["style"] });
98+
}),
99+
);
100+
await resize();
101+
return await firstFrame;
102+
}
103+
61104
async function showDashboard(page: Page) {
62105
const settingsKey = controlUiBundledSettingsStorageKey(controlUi.baseUrl);
63106
await page.addInitScript(
@@ -161,6 +204,69 @@ describeControlUiE2e("Board split transcript restore", () => {
161204
.waitFor({ state: "visible", timeout: 2_000 });
162205
}, 120_000);
163206

207+
it("keeps adjacent Board chat rows separated throughout a real side-panel resize", async () => {
208+
const context = await browser.newContext({ viewport: { width: 1720, height: 1250 } });
209+
contexts.add(context);
210+
try {
211+
const page = await context.newPage();
212+
const now = Date.now();
213+
await installMockGateway(page, {
214+
sessionKey,
215+
featureMethods: ["board.get", "chat.history", "chat.metadata", "chat.startup"],
216+
methodResponses: { "board.get": boardSnapshot("right") },
217+
historyMessages: [
218+
{
219+
role: "assistant",
220+
content:
221+
"Created **Project Board** with a full-screen four-column dashboard:\n\n- Working\n- Idle\n- Review\n- Complete\n\nThe board can refresh active work and show a concise operator summary.\n\nSource: [project-board.html](project-board.html)\n\n" +
222+
"Keep the work board visible while tracking active sessions, reviews, approvals, and completed tasks. ".repeat(
223+
8,
224+
),
225+
timestamp: now - 1,
226+
},
227+
{
228+
role: "user",
229+
content: "Please use the existing work board feature.",
230+
timestamp: now,
231+
},
232+
],
233+
});
234+
235+
await showDashboard(page);
236+
const sidePanel = page.locator(".side-panel");
237+
await page.getByText("Source: project-board.html", { exact: false }).waitFor();
238+
await page.getByText("Please use the existing work board feature.").waitFor();
239+
const initialWidth = await sidePanel.evaluate(
240+
(element) => element.getBoundingClientRect().width,
241+
);
242+
243+
const divider = page.getByRole("separator", { name: "Resize side panel" });
244+
const dividerBounds = await divider.boundingBox();
245+
expect(dividerBounds).not.toBeNull();
246+
const startX = dividerBounds!.x + dividerBounds!.width / 2;
247+
const pointerY = dividerBounds!.y + Math.min(80, dividerBounds!.height / 2);
248+
await page.mouse.move(startX, pointerY);
249+
await page.mouse.down();
250+
const frame = await firstSidebarResizeFrame(page, () =>
251+
page.mouse.move(startX + 64, pointerY),
252+
);
253+
await page.mouse.up();
254+
255+
expect(frame.width).toBeLessThan(initialWidth);
256+
expect(
257+
frame.rowGap,
258+
`first frame width=${frame.width}px; assistant-to-user gap=${frame.assistantUserGap}px`,
259+
).toBeGreaterThanOrEqual(0);
260+
expect(
261+
frame.assistantUserGap,
262+
`assistant text overlaps the user bubble at width=${frame.width}px`,
263+
).toBeGreaterThanOrEqual(0);
264+
} finally {
265+
contexts.delete(context);
266+
await context.close();
267+
}
268+
}, 120_000);
269+
164270
it("closes and reopens the whole multi-tab dashboard side panel", async () => {
165271
const context = await browser.newContext({ viewport: { width: 1400, height: 900 } });
166272
contexts.add(context);

‎ui/src/pages/chat/components/chat-sidebar-region.runtime.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { t } from "../../../i18n/index.ts";
1515
import { OpenClawLightDomElement } from "../../../lit/openclaw-element.ts";
1616
import { sidebarPanelDefinitions } from "../chat-pane-embedded-panels.ts";
1717
import {
18+
SIDEBAR_GEOMETRY_COMMIT_EVENT,
1819
SIDEBAR_MIN_HEIGHT_PX,
1920
SIDEBAR_MIN_WIDTH_PX,
2021
sidebarDock,
@@ -371,7 +372,13 @@ class ChatSidebarRegion extends OpenClawLightDomElement {
371372
protected override updated() {
372373
const root = this.parentElement?.querySelector<HTMLElement>(".sidebar-region__right-runtime");
373374
if (root) {
375+
const previousWidth = root.querySelector<HTMLElement>(".side-panel")?.style.width;
374376
renderTemplate(this.renderPanel(), root);
377+
const panel = root.querySelector<HTMLElement>(".side-panel");
378+
// Wrapped row heights must update with their new width before the same paint.
379+
if (panel && previousWidth !== undefined && panel.style.width !== previousWidth) {
380+
panel.dispatchEvent(new Event(SIDEBAR_GEOMETRY_COMMIT_EVENT, { bubbles: true }));
381+
}
375382
}
376383
}
377384

‎ui/src/pages/chat/components/chat-transcript-controller.test.ts‎

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { html, nothing, render } from "lit";
55
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
66
import { createDeferred } from "../../../../../test/helpers/promise.js";
77
import { createTestTranscript, stubAnimationFrames } from "../chat-view.test-helpers.ts";
8+
import { SIDEBAR_GEOMETRY_COMMIT_EVENT } from "../sidebar-layout.ts";
89
import { renderChatThread } from "./chat-thread.ts";
9-
import type { TranscriptRow } from "./chat-transcript-controller.ts";
10+
import { ChatTranscriptController, type TranscriptRow } from "./chat-transcript-controller.ts";
1011
import {
1112
flushDeferredRowPrune,
1213
installTranscriptDomMocks,
@@ -319,6 +320,64 @@ describe("chat transcript controller", () => {
319320
transcript.hostDisconnected();
320321
});
321322

323+
it("remeasures every visible pane transcript while preserving hidden transcript rows", async () => {
324+
const host = Object.assign(document.body.appendChild(document.createElement("div")), {
325+
addController: vi.fn(),
326+
removeController: vi.fn(),
327+
requestUpdate: vi.fn(),
328+
updateComplete: Promise.resolve(true),
329+
});
330+
const main = new ChatTranscriptController(host);
331+
const detail = new ChatTranscriptController(host);
332+
const mainPanel = host.appendChild(document.createElement("div"));
333+
const detailPanel = host.appendChild(document.createElement("div"));
334+
const mainProps = threadProps("pane-geometry-main", "agent:main:geometry-main");
335+
const detailProps = threadProps("pane-geometry-detail", "agent:main:geometry-detail");
336+
const renderTranscripts = () => {
337+
render(renderChatThread(mainProps, main), mainPanel);
338+
render(renderChatThread(detailProps, detail), detailPanel);
339+
main.hostUpdated();
340+
detail.hostUpdated();
341+
};
342+
343+
renderTranscripts();
344+
main.hostConnected();
345+
detail.hostConnected();
346+
await flushDeferredRowPrune();
347+
renderTranscripts();
348+
349+
const mainScroller = expectDefined(
350+
mainPanel.querySelector<HTMLElement>(".chat-thread"),
351+
"main transcript scroll element",
352+
);
353+
const detailScroller = expectDefined(
354+
detailPanel.querySelector<HTMLElement>(".chat-thread"),
355+
"detail transcript scroll element",
356+
);
357+
mainScroller.getBoundingClientRect = () => new DOMRect(0, 0, 640, 600);
358+
detailScroller.getBoundingClientRect = () =>
359+
detailPanel.hidden ? new DOMRect() : new DOMRect(0, 0, 640, 600);
360+
361+
transcriptDomState.measuredRowHeight = 180;
362+
detailPanel.dispatchEvent(new Event(SIDEBAR_GEOMETRY_COMMIT_EVENT, { bubbles: true }));
363+
renderTranscripts();
364+
expect(transcriptRows(mainPanel)[1]?.style.transform).toBe("translateY(180px)");
365+
expect(transcriptRows(detailPanel)[1]?.style.transform).toBe("translateY(180px)");
366+
367+
detailPanel.hidden = true;
368+
for (const row of transcriptRows(detailPanel)) {
369+
Object.defineProperty(row, "offsetHeight", { configurable: true, value: 0 });
370+
}
371+
transcriptDomState.measuredRowHeight = 240;
372+
detailPanel.dispatchEvent(new Event(SIDEBAR_GEOMETRY_COMMIT_EVENT, { bubbles: true }));
373+
renderTranscripts();
374+
375+
expect(transcriptRows(mainPanel)[1]?.style.transform).toBe("translateY(240px)");
376+
expect(transcriptRows(detailPanel)[1]?.style.transform).toBe("translateY(180px)");
377+
main.hostDisconnected();
378+
detail.hostDisconnected();
379+
});
380+
322381
it.each([
323382
{ label: "end-pinned", distanceFromEnd: 0, expectedCalls: 1 },
324383
{ label: "scrolled away", distanceFromEnd: 100, expectedCalls: 0 },

‎ui/src/pages/chat/components/chat-transcript-controller.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
saveChatSessionScrollPosition,
2323
type ChatSessionScrollPosition,
2424
} from "../scroll.ts";
25+
import { SIDEBAR_GEOMETRY_COMMIT_EVENT } from "../sidebar-layout.ts";
2526
import { extractTranscriptRange, previewTranscriptRowKeys } from "./chat-transcript-range.ts";
2627

2728
export type TranscriptRow<T = unknown> =
@@ -150,6 +151,15 @@ class ChatSessionVirtualizerHost implements ReactiveControllerHost, ChatTranscri
150151
instance.resizeItem(index, size);
151152
}
152153
}
154+
private readonly handleGeometryCommit = () => {
155+
const rect = this.scrollElement?.getBoundingClientRect();
156+
if (!rect || rect.width === 0 || rect.height === 0) {
157+
return;
158+
}
159+
// The viewport observer must not repeat this committed width's row scan.
160+
this.observedWidth = Math.round(rect.width);
161+
this.measureConnectedRows();
162+
};
153163
private queueConnectedRowMeasure(): void {
154164
if (this.pendingRowMeasureFrame !== null) {
155165
return;
@@ -303,6 +313,9 @@ class ChatSessionVirtualizerHost implements ReactiveControllerHost, ChatTranscri
303313
return;
304314
}
305315
this.connected = true;
316+
if (this.host instanceof HTMLElement) {
317+
this.host.addEventListener(SIDEBAR_GEOMETRY_COMMIT_EVENT, this.handleGeometryCommit);
318+
}
306319
for (const controller of this.controllers) {
307320
controller.hostConnected?.();
308321
}
@@ -333,6 +346,9 @@ class ChatSessionVirtualizerHost implements ReactiveControllerHost, ChatTranscri
333346
return;
334347
}
335348
this.connected = false;
349+
if (this.host instanceof HTMLElement) {
350+
this.host.removeEventListener(SIDEBAR_GEOMETRY_COMMIT_EVENT, this.handleGeometryCommit);
351+
}
336352
for (const controller of this.controllers) {
337353
controller.hostDisconnected?.();
338354
}

‎ui/src/pages/chat/sidebar-layout.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export type {
1515

1616
const SIDEBAR_DEFAULT_WIDTH_PX = 480;
1717
const SIDEBAR_DEFAULT_HEIGHT_PX = 360;
18+
export const SIDEBAR_GEOMETRY_COMMIT_EVENT = "openclaw-sidebar-geometry-commit";
1819
export const SIDEBAR_MIN_WIDTH_PX = 260;
1920
export const SIDEBAR_MIN_HEIGHT_PX = 220;
2021
const SIDEBAR_MAX_WIDTH_PX = 1_200;

0 commit comments

Comments
 (0)