fix(webui): stabilize thread during IME input
This commit is contained in:
@@ -186,6 +186,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
||||
const pendingPromptJumpRef = useRef<string | null>(null);
|
||||
const restoreScrollAfterPrependRef =
|
||||
useRef<{ height: number; top: number } | null>(null);
|
||||
const composerInputScrollTopRef = useRef<number | null>(null);
|
||||
const composerDockHeightRef = useRef(0);
|
||||
const [atBottom, setAtBottom] = useState(true);
|
||||
const [composerDockHeight, setComposerDockHeight] = useState(0);
|
||||
@@ -688,9 +689,23 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
||||
data-testid="thread-composer-dock"
|
||||
onInputCapture={(event) => {
|
||||
if (event.target instanceof HTMLTextAreaElement) {
|
||||
composerInputScrollTopRef.current = scrollRef.current?.scrollTop ?? null;
|
||||
threadMotionRef.current?.handleComposerInput();
|
||||
}
|
||||
}}
|
||||
onInput={(event) => {
|
||||
if (!(event.target instanceof HTMLTextAreaElement)) return;
|
||||
const previousScrollTop = composerInputScrollTopRef.current;
|
||||
composerInputScrollTopRef.current = null;
|
||||
const scrollEl = scrollRef.current;
|
||||
if (scrollEl && previousScrollTop !== null) {
|
||||
// Textarea autosizing briefly collapses to `height: auto` while
|
||||
// measuring. Chrome can clamp the sibling thread scrollport in
|
||||
// that intermediate layout; restore it before paint, then let
|
||||
// ResizeObserver handle any real final composer height change.
|
||||
scrollEl.scrollTop = previousScrollTop;
|
||||
}
|
||||
}}
|
||||
className={cn(
|
||||
"row-start-2 z-10 w-full",
|
||||
hasMessages ? "relative bg-background" : "relative self-center",
|
||||
|
||||
Reference in New Issue
Block a user