Skip to content

Commit 8130737

Browse files
committed
chore(chat): trim duplicated comments on the prompt editor autosize
The failure mode was documented in four places. Keeps one canonical explanation next to the guard and leaves only the per-test whys the test names do not already carry.
1 parent 43d4584 commit 8130737

2 files changed

Lines changed: 15 additions & 35 deletions

File tree

apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/prompt-editor/prompt-editor.test.tsx

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@ let editorWidth = 700
3333
let autosizeCalls = 0
3434

3535
/**
36-
* Mirrors the real observer's contract closely enough to test the width guard.
37-
* `observe` only registers the target — real deliveries, including the initial
38-
* one browsers send, are asynchronous, so every test drives them explicitly via
39-
* {@link resizeTo} / {@link FakeResizeObserver.deliverAll}. Delivering inside
36+
* `observe` only registers the target: real deliveries, including the initial
37+
* one, are asynchronous, so tests drive them explicitly. Delivering inside
4038
* `observe` would hide the window between the mount-time measure and the first
41-
* notification, which is exactly where a width change can be missed.
39+
* notification exactly where a width change can be missed.
4240
*/
4341
class FakeResizeObserver implements ResizeObserver {
4442
private static instances: FakeResizeObserver[] = []
@@ -78,7 +76,6 @@ class FakeResizeObserver implements ResizeObserver {
7876
return FakeResizeObserver.instances.length
7977
}
8078

81-
/** Delivers a resize notification to every live observer, as a reflow would. */
8279
static deliverAll() {
8380
for (const instance of [...FakeResizeObserver.instances]) instance.deliver()
8481
}
@@ -109,7 +106,6 @@ function mountEditor() {
109106
}
110107
}
111108

112-
/** Applies a new editor width and delivers the resulting resize notification. */
113109
function resizeTo(width: number, wrappedHeight: number) {
114110
editorWidth = width
115111
contentHeight = wrappedHeight
@@ -159,12 +155,6 @@ describe('PromptEditor autosize', () => {
159155
unmount()
160156
})
161157

162-
/**
163-
* The regression: the textarea carries an inline pixel height, so without a
164-
* width-driven re-measure a narrower editor paints rewrapped overlay text
165-
* below the textarea's box — visible text with no hit target, which swallows
166-
* clicks instead of placing the caret.
167-
*/
168158
it('re-measures when the editor width changes so no text falls outside the textarea', () => {
169159
const { textarea, unmount } = mountEditor()
170160
settle()
@@ -187,12 +177,7 @@ describe('PromptEditor autosize', () => {
187177
unmount()
188178
})
189179

190-
/**
191-
* `observe` registers the target, but the first notification arrives a frame
192-
* later. A sidebar or side-panel transition can change the width inside that
193-
* window, so the first delivery must be measured like any other rather than
194-
* trusted to confirm the width the mount-time measure used.
195-
*/
180+
/** Distinct from the case above: here the width moves before any delivery lands. */
196181
it('re-measures on the first delivery when the width changed before it arrived', () => {
197182
const { textarea, unmount } = mountEditor()
198183
expect(textarea.style.height).toBe('240px')
@@ -203,11 +188,7 @@ describe('PromptEditor autosize', () => {
203188
unmount()
204189
})
205190

206-
/**
207-
* `autosize` writes the textarea's height, which grows the scroller and
208-
* re-notifies this observer. Re-measuring on an unchanged width would make
209-
* that a feedback loop.
210-
*/
191+
/** The height `autosize` writes re-notifies this observer, so this guard breaks the loop. */
211192
it('ignores resize notifications that do not change the width', () => {
212193
const { textarea, unmount } = mountEditor()
213194
settle()

apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/prompt-editor/prompt-editor.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,17 @@ export function PromptEditor({
103103
}, [value, autosize])
104104

105105
/**
106-
* Re-measure when the editor's width changes. The textarea carries an inline
107-
* pixel height, so a width change (window resize, sidebar or side-panel
108-
* toggle, chat column reflow) rewraps the text taller while the box stays at
109-
* its old height. The mirror overlay paints the full text regardless, so the
110-
* spilled lines render over the scroller with no textarea beneath them —
111-
* visible, scrollable text that swallows clicks instead of placing the caret.
106+
* The textarea carries an inline pixel height, so a width change (window
107+
* resize, sidebar toggle, chat column reflow) rewraps the text taller while
108+
* the box stays at its old height. The mirror overlay paints the full text
109+
* regardless, so the spilled lines render over the scroller with no textarea
110+
* beneath them — visible, scrollable text that swallows clicks instead of
111+
* placing the caret.
112112
*
113-
* Only width is compared: `autosize` writes the textarea's height, which grows
114-
* the scroller until its cap and re-notifies this observer, so reacting to
115-
* height would feed itself. The first delivery is measured like any other —
116-
* the width can change between the mount-time measure and `observe()`, and
117-
* re-measuring an unchanged width only writes the same height back.
113+
* Only width is compared: `autosize` writes the textarea's height, which
114+
* re-notifies this observer, so reacting to height would feed itself. The
115+
* first delivery is measured like any other — the width can change between
116+
* the mount-time measure and `observe()`.
118117
*/
119118
useEffect(() => {
120119
const scroller = scrollerRef.current

0 commit comments

Comments
 (0)