Skip to content

Commit d996320

Browse files
committed
fix(ui): prevent dashboard chat messages from overlapping
1 parent 9386ac0 commit d996320

4 files changed

Lines changed: 49 additions & 6 deletions

File tree

‎ui/src/e2e/skills-owner-selection.e2e.test.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ suite.define(() => {
3131

3232
await page.goto(`${suite.server.baseUrl}skills`);
3333
await gateway.waitForRequest("skills.status");
34-
await expect
35-
.poll(() => gateway.getRequests("skills.status"))
36-
.toEqual([expect.objectContaining({ params: { agentId: "main" } })]);
3734
await page.getByText("No skills found.").waitFor();
35+
const requests = await gateway.getRequests("skills.status");
36+
expect(requests.length).toBeGreaterThan(0);
37+
expect(requests.map((request) => request.params)).toEqual(
38+
requests.map(() => ({ agentId: "main" })),
39+
);
3840
});
3941
});
4042
});

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,27 @@ describe("chat transcript controller", () => {
5151
}
5252
});
5353

54+
it("measures newly inserted rows after Lit connects them", async () => {
55+
// Lit invokes ref callbacks while a new row is still detached. Browsers
56+
// report a zero offsetHeight there, which must not become the row's
57+
// durable virtual size before the following user bubble is positioned.
58+
transcriptDomState.detachedRowHeight = 0;
59+
const transcript = createTestTranscript();
60+
const container = document.body.appendChild(document.createElement("div"));
61+
const props = threadProps("pane-commentary-insert", "agent:main:session-a", [
62+
{ role: "assistant", content: "commentary", timestamp: 1_000 },
63+
{ role: "user", content: "next turn", timestamp: 2_000 },
64+
]);
65+
66+
render(renderChatThread(props, transcript), container);
67+
transcript.hostConnected();
68+
transcript.hostUpdated();
69+
await flushDeferredRowPrune();
70+
render(renderChatThread(props, transcript), container);
71+
72+
expect(transcriptRows(container)[1]?.style.transform).toBe("translateY(100px)");
73+
});
74+
5475
it("pauses an unmeasurable restore until loading commits an empty transcript", () => {
5576
const transcript = createTestTranscript();
5677
const container = document.body.appendChild(document.createElement("div"));

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,22 @@ class ChatSessionVirtualizerHost implements ReactiveControllerHost, ChatTranscri
132132
if (!callback) {
133133
callback = (element?: Element) => {
134134
if (element instanceof HTMLElement) {
135-
this.virtualizerController.getVirtualizer().measureElement(element);
135+
if (element.isConnected) {
136+
this.virtualizerController.getVirtualizer().measureElement(element);
137+
} else {
138+
// Lit invokes refs before the row is connected. Measuring a new
139+
// key there records offsetHeight=0, so a following row can share
140+
// its transform and paint over it until ResizeObserver catches up.
141+
queueMicrotask(() => {
142+
if (
143+
element.isConnected &&
144+
element.dataset.virtualRowKey === key &&
145+
this.rowIndexesByKey.has(key)
146+
) {
147+
this.virtualizerController.getVirtualizer().measureElement(element);
148+
}
149+
});
150+
}
136151
return;
137152
}
138153
// Re-stamps (e.g. the chat<->dashboard face switch) re-invoke each

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { resetThreadPresentation } from "./chat-thread-interactions.ts";
44

55
export const observedElements = new Set<Element>();
66
export const resizeObservers = new Set<RecordingResizeObserver>();
7-
export const transcriptDomState = { measuredRowHeight: 100 };
7+
export const transcriptDomState = { measuredRowHeight: 100, detachedRowHeight: 100 };
88

99
class RecordingResizeObserver implements ResizeObserver {
1010
private readonly targets = new Set<Element>();
@@ -95,9 +95,14 @@ export function installTranscriptDomMocks(): void {
9595
observedElements.clear();
9696
resizeObservers.clear();
9797
transcriptDomState.measuredRowHeight = 100;
98+
transcriptDomState.detachedRowHeight = 100;
9899
vi.stubGlobal("ResizeObserver", RecordingResizeObserver);
99100
vi.spyOn(HTMLElement.prototype, "offsetHeight", "get").mockImplementation(
100-
() => transcriptDomState.measuredRowHeight,
101+
function (this: HTMLElement) {
102+
return this.isConnected
103+
? transcriptDomState.measuredRowHeight
104+
: transcriptDomState.detachedRowHeight;
105+
},
101106
);
102107
vi.spyOn(Element.prototype, "getBoundingClientRect").mockReturnValue({
103108
x: 0,

0 commit comments

Comments
 (0)