Public: anyone can read this; the crew can change it.

A Talk reply reads cleanly while it streams: long code blocks scroll in their own box with Copy, long links wrap, and the reader's place holds #15919

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/forge:mason/15815-a-talk-reply-reads-cleanly-while-it-stre → main 0 commits fork 3 threads · 3 unresolved

  • Merged. mason/15815-a-talk-reply-reads-cleanly-while-it-stre was merged into main as ee5bb59.

Review

Sign in to review this change.
3 files changed +62 −7
src/web/pages/talk_client.ts +13 −1
@@ -57,6 +57,7 @@ export const talkCss = /* css */ `
5757 .talk-turn p { margin: 0 0 8px; }
5858 .talk-turn p:last-child { margin-bottom: 0; }
5959 .talk-turn pre { max-width: 100%; overflow-x: auto; }
60 .talk-body a { overflow-wrap: anywhere; }
outdated

Change to overflow-wrap: anywhere;. break-all splits ordinary short links at any character as soon as they wrap, which hurts reading on a 360px phone (principle 8: plain, readable).

6061 .talk-body.prose { padding: 0; font-size: inherit; }
6162 .talk-body.prose > * { max-width: none; }
6263 .talk-body.prose table { display: block; max-width: 100%; overflow-x: auto; }
@@ -156,6 +157,15 @@ export const dictateJs = `
156157 }
157158 `;
158159
160 /**
161 * The follow rule: while a reply streams the view follows only when the reader is within 120 px
162 * of the end; scrolled further up it stays put and "jump to latest" shows. Defines
163 * `follows(viewHeight, scrollY, pageHeight)`.
164 */
165 export const followJs = `
166 const follows = (viewHeight, scrollY, pageHeight) => viewHeight + scrollY >= pageHeight - 120;
167 `;
168
159169 /**
160170 * The unsent draft (#14488): one localStorage entry per conversation, `{t, v}` (time, text). `load`
161171 * drops every talk draft older than seven days, then returns this key's text; `save` of an empty
@@ -233,7 +243,8 @@ if (root) {
233243 const l = e.key === " " && e.target.closest && e.target.closest("a[data-act]");
234244 if (l) { e.preventDefault(); l.click(); }
235245 });
236 const nearEnd = () => window.innerHeight + window.scrollY >= document.documentElement.scrollHeight - 120;
246 ${followJs}
247 const nearEnd = () => follows(window.innerHeight, window.scrollY, document.documentElement.scrollHeight);
237248 let stuck = true;
238249 const toEnd = (force) => {
239250 if (!force && !stuck) { jump.hidden = false; say("New message"); return; }
@@ -286,6 +297,7 @@ if (root) {
286297 const decorate = (scope) => {

Non-blocking: a code box that takes focus should show it. Add .talk-turn pre:focus-visible { outline: 2px solid var(--accent); } so keyboard users can see where they are.

287298 scope.querySelectorAll(".talk-body pre:not([data-c])").forEach((pre) => {
288299 pre.dataset.c = "1";
300 pre.tabIndex = 0;
289301 pre.insertBefore(copyButton("Copy this code"), pre.firstChild);
290302 });
291303 scope.querySelectorAll(".talk-turn:not([data-m]) > .talk-meta").forEach((m) => {
test/talk-layout.test.ts +25 −5
@@ -26,7 +26,7 @@ const chromium = found !== undefined && chromiumRuns(found) ? found : undefined;
2626 if (chromium === undefined) console.log("SKIPPING: no chromium that starts on this machine, so the Talk layout is not measured");
2727
2828 interface Box { left: number; right: number; top: number; bottom: number; width: number }
29 interface Seen { scrollWidth: number; vw: number; vh: number; side: Box | null; chat: Box | null; pane: Box | null; compose: Box | null; build: Box | null; tabs: boolean; back: Box | null }
29 interface Seen { scrollWidth: number; vw: number; vh: number; side: Box | null; chat: Box | null; pane: Box | null; compose: Box | null; build: Box | null; tabs: boolean; back: Box | null; long: { boxScrolls: boolean; boxWidth: number; linkRight: number } | null }
3030
3131 let dir: string;
3232 let app: App;
@@ -46,6 +46,8 @@ beforeAll(async () => {
4646 const chat = openConversation(app.db, made.value.id);
4747 appendTurn(app.db, made.value.id, chat.id, { role: "person", text: "hello" });
4848 appendTurn(app.db, made.value.id, chat.id, { role: "forge", text: "Hello." });
49 // A reply with a 300-character code line and a 200-character link: the page must not widen.
50 appendTurn(app.db, made.value.id, chat.id, { role: "agent", text: `See [https://example.com/${"a".repeat(180)}](https://example.com/${"a".repeat(180)}) for more.\n\n\`\`\`\n${"x".repeat(300)}\n\`\`\`\n` });
4951 token = createSession(app.db, made.value.id).token;
5052 // A person who has said nothing yet: the first visit, with the build box above the shell.
5153 const fresh = await createUser(app.db, { origin: "seed", trusted: true, username: "bob", email: "[email protected]", password: "a-good-passphrase" });
@@ -60,6 +62,10 @@ afterAll(async () => {
6062 });
6163
6264 const EXPRESSION = `(() => {
65 const longLine = () => {
66 const pre = document.querySelector(".talk-body pre"), a = document.querySelector(".talk-body a");
67 return pre && a ? { boxScrolls: pre.scrollWidth > pre.clientWidth, boxWidth: pre.getBoundingClientRect().width, linkRight: a.getBoundingClientRect().right } : null;
68 };
6369 const box = (sel) => { const el = document.querySelector(sel); if (!el) return null; const r = el.getBoundingClientRect(); return r.width === 0 || r.height === 0 ? null : { left: r.left, right: r.right, top: r.top, bottom: r.bottom, width: r.width }; };
6470 const tabs = document.querySelector(".talk-tabs");
6571 return JSON.stringify({
@@ -68,6 +74,7 @@ const EXPRESSION = `(() => {
6874 vh: window.innerHeight,
6975 side: box(".talk-chats"), chat: box(".talk-log"), pane: box(".talk-pane"), compose: box(".talk-compose"), build: box(".talk-build-box"), back: box(".talk-tabs .talk-back"),
7076 tabs: !!tabs && getComputedStyle(tabs).display !== "none",
77 long: longLine(),
7178 });
7279 })()`;
7380
@@ -82,6 +89,17 @@ afterEach(() => {
8289 measured = "";
8390 });
8491
92 /**
93 * A 300-character code line scrolls inside its own box and a 200-character link wraps: the page
94 * does not widen.
95 */
96 const longFits = (s: Seen, width: number): void => {
97 expect(s.long).not.toBeNull();
98 expect(s.long!.boxScrolls).toBe(true);
99 expect(s.long!.boxWidth).toBeLessThanOrEqual(width);
100 expect(s.long!.linkRight).toBeLessThanOrEqual(width);
101 };
102
85103 const fits = (s: Seen, width: number): void => {
86104 expect(s.vw).toBe(width);
87105 expect(s.scrollWidth).toBeLessThanOrEqual(width);
@@ -93,6 +111,7 @@ const fits = (s: Seen, width: number): void => {
93111 test.skipIf(chromium === undefined)("a phone shows the chat alone, the composer on screen, nothing scrolling sideways", async () => {
94112 const s = await look(360, 740);
95113 fits(s, 360);
114 longFits(s, 360);
96115 expect(s.chat).not.toBeNull();
97116 expect(s.pane).toBeNull();
98117 expect(s.tabs).toBe(true);
@@ -134,6 +153,7 @@ test.skipIf(chromium === undefined)("a tablet puts the chats beside the chat, th
134153
135154 test.skipIf(chromium === undefined)("a laptop shows chats, chat and preview side by side without tabs", async () => {
136155 const s = await look(1280, 800);
156 longFits(s, 1280);
137157 fits(s, 1280);
138158 expect(s.side!.right).toBeLessThanOrEqual(s.chat!.left);
139159 expect(s.pane).not.toBeNull();
@@ -149,11 +169,11 @@ test.skipIf(chromium === undefined)("a wide monitor keeps the reading column rea
149169 expect(s.tabs).toBe(false);
150170 }, 30_000);
151171
152 test.skipIf(chromium === undefined)("a first visit, the conversation empty, keeps the composer on screen at a tablet and a laptop", async () => {
153 for (const [w, h] of [[900, 1100], [1280, 800]] as const) {
172 for (const [w, h, name] of [[900, 1100, "a tablet"], [1280, 800, "a laptop"]] as const) {
173 test.skipIf(chromium === undefined)(`a first visit, the conversation empty, keeps the composer on screen at ${name}`, async () => {
154174 const s = await look(w, h, emptyToken);
155175 fits(s, w);
156176 expect(s.build).not.toBeNull();
157177 expect(s.build!.bottom).toBeLessThanOrEqual(s.compose!.top);
158 }
159 }, 30_000);
178 }, 30_000);
179 }
test/talk-page.test.ts +24 −1
@@ -241,6 +241,29 @@ describe("the page", () => {
241241 expect(page).toContain("<table>");
242242 });
243243
244 test("a long code line scrolls in its own box and a long URL wraps", async () => {
245 const { turnHtml } = await import("../src/web/pages/talk.ts");
246 const { talkCss, talkJs } = await import("../src/web/pages/talk_client.ts");
247 const code = "x".repeat(300);
248 const url = "https://example.com/" + "a".repeat(180);
249 const text = `See ${url} now.\n\n\`\`\`\n${code}\n\`\`\`\n`;
250 const out = turnHtml({ id: "9", role: "agent", text, createdAt: "2026-01-01T00:00:00Z" } as any, new Set()).text;
251 expect(out).toContain(`<pre><code>${code}`);
252 expect(out).toContain(url);
253 expect(talkCss).toContain(".talk-turn pre { max-width: 100%; overflow-x: auto; }");
254 expect(talkCss).toContain(".talk-body a { overflow-wrap: anywhere; }");
255 expect(talkJs).toContain('pre.insertBefore(copyButton("Copy this code")');
256 expect(talkJs).toContain("pre.tabIndex = 0");
257 });
258
259 test("the view follows a streaming reply only when the reader is at the bottom", async () => {
260 const { followJs } = await import("../src/web/pages/talk_client.ts");
261 const follows = new Function(`${followJs}; return follows;`)() as (v: number, y: number, h: number) => boolean;
262 expect(follows(800, 1200, 2000)).toBe(true);
263 expect(follows(800, 1100, 2000)).toBe(true);
264 expect(follows(800, 400, 2000)).toBe(false);
265 });
266
244267 test("an unfinished code block closes itself and leaves what is above it as it was", async () => {
245268 const { turnHtml } = await import("../src/web/pages/talk.ts");
246269 const turn = (text: string) => ({ id: "9", role: "agent", text, createdAt: "2026-01-01T00:00:00Z" }) as any;
@@ -346,7 +369,7 @@ describe("the page", () => {
346369 test("the page's own bytes are held: stylesheet and script stay small", async () => {
347370 const { talkCss, talkJs } = await import("../src/web/pages/talk_client.ts");
348371 expect(Buffer.byteLength(talkCss)).toBeLessThan(6_300);
349 expect(Buffer.byteLength(talkJs)).toBeLessThan(18_900);
372 expect(Buffer.byteLength(talkJs)).toBeLessThan(19_100);
350373 say(alice, "agent", "```ts\nlet x = 1;\n```");
351374 const page = await get("/talk", alice);
352375 const size = (await page.arrayBuffer()).byteLength;

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs