A local-first multi-agent app development platform, built on PenguinHarness
fix(web): typing in the composer no longer moves the conversation (#1052)
lmliheng049563eb9365
diff --git a/changelog/unreleased/2026-10-12-composer-typing-keeps-transcript.md b/changelog/unreleased/2026-10-12-composer-typing-keeps-transcript.mdnew file mode 100644index 00000000..46bba64f--- /dev/null+++ b/changelog/unreleased/2026-10-12-composer-typing-keeps-transcript.md@@ -0,0 +1,17 @@+# Typing in the composer no longer moves the conversation++- **Date:** 2026-10-12+- **Type:** fix+- **Scope:** `web`++[中文版](2026-10-12-composer-typing-keeps-transcript.zh.md)++Ported from upstream PenguinHarness (#1052, commit `fc205d99`).++The composer sized its text box on every keystroke by collapsing it to `height: auto` and reading its content height. That read laid the page out with the composer shorter, so the message list above it, sized by what the composer leaves, grew for that moment, and the browser clamped a list parked at the bottom to the taller viewport's bottom. Restoring the height did not give the offset back.++- With a draft of one or two lines the list slid by a device pixel at some theme and text-size combinations, for example Frost at text size L on a 2× screen. While a reply streamed, each update snapped it back to the bottom and the next keystroke slid it again, so the list shook as the user typed.+- With a draft of three lines or more the first keystroke scrolled the list back by the extra lines, and auto-follow read the jump as the user scrolling away, so a streaming reply stopped scrolling into view and the jump-to-latest button appeared.+- The box is still collapsed and measured, but its parent is held at its current height while that happens, so nothing outside the composer moves. The same fix applies to the company channel composer.++No API, wire format or stored data changes.diff --git a/changelog/unreleased/2026-10-12-composer-typing-keeps-transcript.zh.md b/changelog/unreleased/2026-10-12-composer-typing-keeps-transcript.zh.mdnew file mode 100644index 00000000..66ebfbb3--- /dev/null+++ b/changelog/unreleased/2026-10-12-composer-typing-keeps-transcript.zh.md@@ -0,0 +1,17 @@+# 在输入框打字不再带动对话++- **Date:** 2026-10-12+- **Type:** fix+- **Scope:** `web`++[English](2026-10-12-composer-typing-keeps-transcript.md)++移植自上游 PenguinHarness(#1052,提交 `fc205d99`)。++输入框每次按键都会重新计算文本框高度:先把它收成 `height: auto`,再读内容高度。这次读取会让页面按变矮的输入框排一次版,上方按输入框剩余空间定高的消息列表随之瞬间变高,停在底部的列表被浏览器夹到更高视口的底部;高度恢复后,滚动位置却没有退回来。++- 草稿只有一两行时,在部分主题与字号组合下(例如 2 倍屏上白领主题的「大」字号),列表会滑动一个设备像素。回复流式输出期间,每次更新把它拉回底部,下一次按键又让它滑开,于是打字时列表一直在抖。+- 草稿达到三行及以上时,第一次按键就让列表往回滚动多出的那几行,自动跟随把这次跳动当成用户向上滚动,流式回复不再自动滚入视野,「回到最新消息」按钮随之出现。+- 现在仍然收起文本框来测量,但测量期间把它的父元素固定在当前高度,输入框以外的布局不受影响。公司频道的输入框同样修复。++接口、线上格式与已存数据都没有变化。diff --git a/packages/web/src/features/chat/chat-input.tsx b/packages/web/src/features/chat/chat-input.tsxindex a77a629f..dd172a0e 100644--- a/packages/web/src/features/chat/chat-input.tsx+++ b/packages/web/src/features/chat/chat-input.tsx@@ -123,6 +123,7 @@ import {import type { MenuSelectOption, TagInputChip } from "@lmliheng/penguin-ui";import { S } from "../../lib/strings";import { formatBytes, humanizeTokens } from "../../lib/format";+import { fitTextarea } from "../../lib/textarea-fit";import { useLocale } from "../../state/locale";import { useAuth } from "../../state/auth";import { agentDisplayName } from "../../state/project";@@ -1510,12 +1511,15 @@ export function ChatInput({return () => window.removeEventListener("resize", measure);}, [slashOpen, agentSwitchOpen]);- /** Auto-grow the textarea (caps at roughly 6 lines, scrolls internally beyond that). */+ /**+ * Auto-grow the textarea (caps at roughly 6 lines, scrolls internally beyond that). The+ * measurement holds the card's height (see textarea-fit.ts): the transcript above is sized by+ * what the composer leaves, and a collapse it could see would slide it on every keystroke.+ */const autoGrow = () => {const el = textareaRef.current;if (!el) return;- el.style.height = "auto";- el.style.height = `${Math.min(el.scrollHeight, 176)}px`;+ fitTextarea(el, (box) => Math.min(box.scrollHeight, 176));};/**diff --git a/packages/web/src/features/company/channel-composer.tsx b/packages/web/src/features/company/channel-composer.tsxindex ba0c6c97..1ede470a 100644--- a/packages/web/src/features/company/channel-composer.tsx+++ b/packages/web/src/features/company/channel-composer.tsx@@ -45,6 +45,7 @@ import type {} from "react";import { Button, Dropdown, ICON_GAP, MenuLabel, noAutofill } from "@lmliheng/penguin-ui";import { S } from "../../lib/strings";+import { fitTextarea } from "../../lib/textarea-fit";import { PrincipalChip } from "./shared";import {mentionInsertId,@@ -166,13 +167,15 @@ export function ChannelComposer({// The resting height is not set here: `min-h-10` on the box and `h-10` on the button are the// same 2.5rem, so an empty or single-line draft sits exactly as tall as 发送 at every font// scale, and `min-height` outranks the height written below. The row is `items-end`, so the- // button stays welded to the box's bottom edge as the box grows.+ // button stays welded to the box's bottom edge as the box grows. The measurement holds the+ // box's wrapper at its height (see textarea-fit.ts), so the channel's message list above is+ // never resized by the collapse and keeps its place on every keystroke.useLayoutEffect(() => {const el = inputRef.current;if (!el) return;- el.style.height = "auto";- const border = el.offsetHeight - el.clientHeight;- el.style.height = `${Math.min(el.scrollHeight + border, MAX_BOX_PX)}px`;+ fitTextarea(el, (box) =>+ Math.min(box.scrollHeight + box.offsetHeight - box.clientHeight, MAX_BOX_PX),+ );syncLayer();}, [text]);diff --git a/packages/web/src/lib/textarea-fit.ts b/packages/web/src/lib/textarea-fit.tsnew file mode 100644index 00000000..654fd2ed--- /dev/null+++ b/packages/web/src/lib/textarea-fit.ts@@ -0,0 +1,33 @@+/**+ * Sizes an auto-growing textarea to its content without moving anything around it.+ *+ * The box is measured the usual way, collapsed to `height: auto` and its `scrollHeight` read,+ * and that read forces a layout with the box collapsed. Everything sized by what the box leaves+ * moves in that layout. Above a composer that is the transcript, a sibling scroll container+ * whose viewport grows while the composer is collapsed, so the browser clamps its scrollTop to+ * the taller viewport's smaller maximum, and writing the height back does not return the offset.+ * A transcript parked at the bottom would slide on every keystroke: by a device pixel where the+ * collapsed box is a fraction of a pixel shorter than the height it is set to (the theme's+ * fractional spacing unit makes it so at some text sizes), and by whole lines once a draft runs+ * past the two rows the box collapses to, which also reads as the user scrolling up and turns+ * auto-follow off.+ *+ * Holding the box's parent at its current height for the measurement keeps that layout+ * identical outside the parent. The hold is a `min-height`, so a box that grows still pushes the+ * parent (growth shrinks the transcript, which never clamps an offset). The parent's height is+ * read from its computed style rather than its client rect: the rect is scaled by any transform+ * an entrance animation holds, and an offset height is rounded to whole pixels, either of which+ * would let the parent move by the difference.+ */+export function fitTextarea(+ box: HTMLTextAreaElement,+ /** The height to set, read while the box is collapsed: its `scrollHeight`, capped, plus any border it adds back. */+ measure: (collapsed: HTMLTextAreaElement) => number,+): void {+ const parent = box.parentElement;+ const held = parent?.style.minHeight ?? "";+ if (parent) parent.style.minHeight = getComputedStyle(parent).height;+ box.style.height = "auto";+ box.style.height = `${measure(box)}px`;+ if (parent) parent.style.minHeight = held;+}diff --git a/packages/web/test/textarea-fit.test.ts b/packages/web/test/textarea-fit.test.tsnew file mode 100644index 00000000..867e9389--- /dev/null+++ b/packages/web/test/textarea-fit.test.ts@@ -0,0 +1,36 @@+/**+ * Sizing an auto-growing textarea (lib/textarea-fit.ts): the collapse that measures the box+ * happens with the box's parent held at its height, so the layout the measurement forces is the+ * same outside the parent and a transcript parked at the bottom above a composer is not clamped+ * up by it. Afterwards the box has its new height and the parent its own min-height back.+ */+import { describe, expect, it, vi } from "vitest";+import { fitTextarea } from "../src/lib/textarea-fit";++function fakeBox(parentMinHeight: string | null) {+ const parent =+ parentMinHeight === null ? null : { style: { minHeight: parentMinHeight }, height: "131.52px" };+ const box = { style: { height: "66px" }, scrollHeight: 96, parentElement: parent };+ vi.stubGlobal("getComputedStyle", (el: { height: string }) => ({ height: el.height }));+ return { box: box as unknown as HTMLTextAreaElement, parent };+}++describe("fitTextarea", () => {+ it("measures the collapsed box with its parent held at its height, then releases the hold", () => {+ const { box, parent } = fakeBox("2.5rem");+ const seen: { box: string; parent: string | undefined }[] = [];+ fitTextarea(box, (collapsed) => {+ seen.push({ box: collapsed.style.height, parent: parent?.style.minHeight });+ return Math.min(collapsed.scrollHeight, 176);+ });+ expect(seen).toEqual([{ box: "auto", parent: "131.52px" }]);+ expect(box.style.height).toBe("96px");+ expect(parent?.style.minHeight).toBe("2.5rem");+ });++ it("sizes a box without a parent", () => {+ const { box } = fakeBox(null);+ fitTextarea(box, (collapsed) => collapsed.scrollHeight);+ expect(box.style.height).toBe("96px");+ });+});