Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

fix(web-ui): measure transcript after markdown renders (#1131)

Joshua Franceee7c5e560eac
diff --git a/plugins/web-ui/src/chat.ts b/plugins/web-ui/src/chat.ts
index 2258f69d5..339ec810a 100644
--- a/plugins/web-ui/src/chat.ts
+++ b/plugins/web-ui/src/chat.ts
@@ -1294,9 +1294,13 @@ export function createChatSurface(
chatState.host,
);
decorateStreamingTail();
- requestAnimationFrame(() => decorateTextCodeBlocks(chatState.host));
- ctx.composer.resizeComposer();
- scrollTranscript(opts.forceScroll);
+ const host = chatState.host;
+ requestAnimationFrame(() => {
+ if (chatState.host !== host || chatState.agent !== agent || !host.isConnected) return;
+ decorateTextCodeBlocks(host);
+ ctx.composer.resizeComposer();
+ scrollTranscript(opts.forceScroll);
+ });
postCurrentPaneState();
}
diff --git a/plugins/web-ui/test/layout-thrash.test.ts b/plugins/web-ui/test/layout-thrash.test.ts
index 15843a473..5485cfffd 100644
--- a/plugins/web-ui/test/layout-thrash.test.ts
+++ b/plugins/web-ui/test/layout-thrash.test.ts
@@ -55,3 +55,19 @@ test("both pagination paths adjust their anchor without smooth scrolling", () =>
);
assert.equal(anchors?.length, 2);
});
+
+test("chat layout waits for markdown custom elements before measuring the transcript", () => {
+ const fn = chat.match(/function drawActiveChat\([\s\S]*?\n {2}\}/)?.[0] ?? "";
+ const deferred = fn.match(/requestAnimationFrame\(\(\) => \{[\s\S]*?\n {4}\}\);/)?.[0] ?? "";
+ assert.match(deferred, /decorateTextCodeBlocks\(host\)/);
+ assert.match(deferred, /ctx\.composer\.resizeComposer\(\)/);
+ assert.match(deferred, /scrollTranscript\(opts\.forceScroll\)/);
+ assert.doesNotMatch(fn.replace(deferred, ""), /resizeComposer\(|scrollTranscript\(/);
+});
+
+test("deferred chat layout cannot scroll a replacement or detached session", () => {
+ const fn = chat.match(/function drawActiveChat\([\s\S]*?\n {2}\}/)?.[0] ?? "";
+ const guard = fn.indexOf("if (chatState.host !== host || chatState.agent !== agent || !host.isConnected) return;");
+ const measure = fn.indexOf("ctx.composer.resizeComposer()");
+ assert.ok(guard >= 0 && guard < measure);
+});