Commit 50f7bd667 for llama.cpp
commit 50f7bd667452bad95a6005cac6c3a0d4fefb1bd7
Author: Aleksander Grygier <aleksander.grygier@gmail.com>
Date: Sun Dec 6 13:11:21 2026 +0100
ui: keep the chat form responsive while typing in long conversations (#33845)
* ui: keep the chat form responsive while typing in long conversations
Assisted-by: Claude (Opus 5.5 Medium)
* ui: sort StickToBottom's landing fields for the linter
Assisted-by: Claude (Opus 5.5 Medium)
diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatForm.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatForm.svelte
index 3db6dd1cb..56ba83a0a 100644
--- a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatForm.svelte
+++ b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatForm.svelte
@@ -419,7 +419,6 @@
$effect(() => {
void textHeight;
- const fitsOneLine = textLines() < CHAT_FORM_SINGLE_ROW_MAX_TEXT_LINES;
const length = value.length;
// an emptied form tries the one row again; one that wraps while empty keeps the two rows
@@ -427,9 +426,17 @@
lastLength = length;
+ // not a candidate for the one row: nothing to measure, and measuring would force a layout
+ // of the page on every keystroke for nothing
if (!canBeSingleRow) {
isSingleRow = false;
- } else if (isSingleRow && !fitsOneLine) {
+
+ return;
+ }
+
+ const fitsOneLine = textLines() < CHAT_FORM_SINGLE_ROW_MAX_TEXT_LINES;
+
+ if (isSingleRow && !fitsOneLine) {
isSingleRow = false;
wrappedAtLength = length;
} else if (!isSingleRow && length < wrappedAtLength) {
diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormInput/ChatFormInput.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormInput/ChatFormInput.svelte
index 06a456a41..4a9958676 100644
--- a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormInput/ChatFormInput.svelte
+++ b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormInput/ChatFormInput.svelte
@@ -48,8 +48,8 @@
`${settingsStore.config[SETTINGS_KEYS.SHOW_FULL_PATH_IN_MENTIONS]}|${toolsStore.serverHome ?? ''}`
);
- // CSS can not transition a height that follows its content, so the editor's content
- // height is mirrored onto this wrapper as a length the stylesheet transitions
+ // The editor's content height, mirrored onto this wrapper as a length and reported to the
+ // form, which picks its rows by it
$effect(() => {
const content = editor?.getContentDOM();
@@ -193,7 +193,8 @@
min-height: 2.25rem;
max-height: var(--max-message-height);
line-height: 1.5rem;
- transition: height 400ms cubic-bezier(0.3, 1.12, 0.5, 1);
+ /* No height transition: each of its frames fires the form's ResizeObservers, and each of
+ those lays out the whole conversation again */
}
.chat-form-input.expanded {
@@ -204,12 +205,6 @@
min-height: 1.5rem;
}
- @media (prefers-reduced-motion: reduce) {
- .chat-form-input {
- transition: none;
- }
- }
-
/* Every box down to the editor takes the wrapper's height, so the editor scrolls inside it */
.chat-form-input :global(:is(.chat-form-editor, .markdown-content)) {
display: flex;
diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatScreen/ChatScreenForm.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatScreen/ChatScreenForm.svelte
index e0dda24cb..7ed24b1eb 100644
--- a/ui/apps/chat/src/lib/components/app/chat/ChatScreen/ChatScreenForm.svelte
+++ b/ui/apps/chat/src/lib/components/app/chat/ChatScreen/ChatScreenForm.svelte
@@ -43,21 +43,40 @@
if (!formEl) return;
+ // Every write restyles the whole conversation, so it happens only when the rounded height
+ // changes, on the chat screen around the last assistant message that reads it, and in the
+ // next frame: written from this observer, the stick-to-bottom's observer reading the page
+ // height right after would force that restyle and a layout on the spot
+ const heightTarget = formEl.closest<HTMLElement>('.chat-screen') ?? document.documentElement;
+
+ let heightFrame: number | null = null;
+ let lastFormHeight = -1;
+
const updateHeight = () => {
+ heightFrame = null;
+
const height = Math.round(formEl.getBoundingClientRect().height);
- document.documentElement.style.setProperty('--chat-form-height', `${height}px`);
+ if (height === lastFormHeight) return;
+
+ lastFormHeight = height;
+ heightTarget.style.setProperty('--chat-form-height', `${height}px`);
};
updateHeight();
- const resizeObserver = new ResizeObserver(updateHeight);
+ const resizeObserver = new ResizeObserver(() => {
+ heightFrame ??= requestAnimationFrame(updateHeight);
+ });
resizeObserver.observe(formEl);
return () => {
resizeObserver.disconnect();
- document.documentElement.style.removeProperty('--chat-form-height');
+
+ if (heightFrame !== null) cancelAnimationFrame(heightFrame);
+
+ heightTarget.style.removeProperty('--chat-form-height');
};
});
let hasLoadingAttachments = $derived(uploadedFiles.some((f) => f.isLoading));
diff --git a/ui/apps/chat/src/lib/hooks/use-stick-to-bottom.svelte.ts b/ui/apps/chat/src/lib/hooks/use-stick-to-bottom.svelte.ts
index 95bb18c8a..29e462ac6 100644
--- a/ui/apps/chat/src/lib/hooks/use-stick-to-bottom.svelte.ts
+++ b/ui/apps/chat/src/lib/hooks/use-stick-to-bottom.svelte.ts
@@ -98,9 +98,9 @@ export class StickToBottom {
private landingHeight = 0;
/** Set while a new conversation's first message lands at the top of the page. */
private landingHold = false;
+ private landingReleaseTimer: ReturnType<typeof setTimeout> | undefined;
/** The first message is on the page: the hold lets go once the page stops growing. */
private landingSettling = false;
- private landingReleaseTimer: ReturnType<typeof setTimeout> | undefined;
private lastScrollHeight = 0;
private lastScrollTop = 0;
private markPressed = (): void => {