Skip to content

Commit 12cf0f4

Browse files
authored
🤖 fix: chat input initial size bug (#850)
The chat input could appear way too big vertically on initial app launch, then collapse to correct size when text was entered or window was resized. **Root cause:** `useEffect` runs asynchronously after paint, so the initial `scrollHeight` measurement could happen before layout settled, resulting in an incorrect (too large) height. **Fix:** Switch to `useLayoutEffect` which runs synchronously after DOM mutations but before the browser paints, ensuring accurate initial height measurement. --- _Generated with `mux`_
1 parent 735e650 commit 12cf0f4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/browser/components/VimTextArea.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useMemo, useRef, useState } from "react";
1+
import React, { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
22
import type { UIMode } from "@/common/types/mode";
33
import * as vim from "@/browser/utils/vim";
44
import { TooltipWrapper, Tooltip, HelpIndicator } from "./Tooltip";
@@ -64,11 +64,15 @@ export const VimTextArea = React.forwardRef<HTMLTextAreaElement, VimTextAreaProp
6464
const yankBufferRef = useRef<string>("");
6565

6666
// Auto-resize when value changes
67-
useEffect(() => {
67+
// Uses useLayoutEffect to measure and set height synchronously before paint,
68+
// preventing flash of wrong size on initial render
69+
useLayoutEffect(() => {
6870
const el = textareaRef.current;
6971
if (!el) return;
72+
// Reset to auto to get accurate scrollHeight measurement
7073
el.style.height = "auto";
7174
const max = window.innerHeight * 0.5; // 50vh
75+
// scrollHeight gives the full content height; clamp to max
7276
el.style.height = Math.min(el.scrollHeight, max) + "px";
7377
}, [value]);
7478

0 commit comments

Comments
 (0)