Commit 5e4fda8ed for llama.cpp
commit 5e4fda8ed04607671e9a993a7f029515620c0989
Author: maxipesfix <makatchev@gmail.com>
Date: Wed Nov 25 23:43:01 2026 +0900
ui: fix for a chat form update loop with large fonts and long model names (otherwise web interface gets Error 500) (#33037)
* ready for PR
* addressing review comments
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 775b4c295..82ffb3f6a 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
@@ -18,7 +18,7 @@
DialogMcpResourcesBrowser
} from '#lib/components/app/index.ts';
import {
- CHAT_FORM_SINGLE_ROW_MAX_TEXT_PX,
+ CHAT_FORM_SINGLE_ROW_MAX_TEXT_LINES,
CLIPBOARD_CONTENT_QUOTE_PREFIX,
ICON_CLASS_DEFAULT,
INITIAL_FILE_SIZE,
@@ -313,6 +313,7 @@
// wrapped, as the wider row of its own would fit it again and flip it straight back
let textHeight = $state<number | null>(null);
let wrappedAtLength = Infinity;
+ let lastLength = 0;
let canBeSingleRow = $derived(
singleRow &&
!deviceStore.isMobile &&
@@ -331,11 +332,16 @@
$effect(() => {
void textHeight;
- const height = inputRef?.getContentDOM()?.offsetHeight ?? 0;
- const fitsOneLine = height < CHAT_FORM_SINGLE_ROW_MAX_TEXT_PX;
+ const content = inputRef?.getContentDOM();
+ const lineHeight = content ? parseFloat(getComputedStyle(content).lineHeight) : 0;
+ const lines = content && lineHeight ? content.offsetHeight / lineHeight : 0;
+ const fitsOneLine = lines < CHAT_FORM_SINGLE_ROW_MAX_TEXT_LINES;
const length = value.length;
- if (!length) wrappedAtLength = Infinity;
+ // an emptied form tries the one row again; one that wraps while empty keeps the two rows
+ if (!length && lastLength) wrappedAtLength = Infinity;
+
+ lastLength = length;
if (!canBeSingleRow) {
isSingleRow = false;
diff --git a/ui/apps/chat/src/lib/constants/chat-form.constants.ts b/ui/apps/chat/src/lib/constants/chat-form.constants.ts
index ff1d5b4ae..cb0916d2d 100644
--- a/ui/apps/chat/src/lib/constants/chat-form.constants.ts
+++ b/ui/apps/chat/src/lib/constants/chat-form.constants.ts
@@ -5,8 +5,8 @@ export const PROMPT_TRIGGER_PREFIX = '/';
export const NEW_CHAT_DRAFT_KEY = '__new_chat__';
/** Lines of text from which the main chat form expands into its large editor. */
export const CHAT_FORM_EXPAND_MIN_LINES = 4;
-/** Below this text height (a 24px line and change) the main chat form keeps to one row. */
-export const CHAT_FORM_SINGLE_ROW_MAX_TEXT_PX = 36;
+/** Below this text height (a line and change) the main chat form keeps to one row. */
+export const CHAT_FORM_SINGLE_ROW_MAX_TEXT_LINES = 1.5;
/**
* How far the chat form floats above the bottom of the screen: a phone browser's toolbar is
diff --git a/ui/apps/chat/tests/client/chat-form-single-row.svelte.test.ts b/ui/apps/chat/tests/client/chat-form-single-row.svelte.test.ts
index ed8cf499e..623638355 100644
--- a/ui/apps/chat/tests/client/chat-form-single-row.svelte.test.ts
+++ b/ui/apps/chat/tests/client/chat-form-single-row.svelte.test.ts
@@ -10,6 +10,9 @@ import { render } from 'vitest-browser-svelte';
const PHONE = { height: 844, width: 390 };
const DESKTOP = { height: 900, width: 1280 };
+// the text's height arrives with the next layout
+const nextLayout = () =>
+ new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)));
async function renderForm() {
const { container } = render(ChatFormTestWrapper, { expandable: true, singleRow: true });
@@ -26,8 +29,7 @@ async function renderForm() {
const write = async (text: string) => {
editor.dispatch({ changes: { from: 0, insert: text, to: editor.state.doc.length } });
await tick();
- // the text's height arrives with the next layout
- await new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)));
+ await nextLayout();
};
return { isSingleRow, write };
@@ -35,6 +37,8 @@ async function renderForm() {
describe('ChatForm single row', () => {
afterEach(async () => {
+ document.documentElement.style.fontSize = '';
+ document.body.style.width = '';
await page.viewport(DESKTOP.width, DESKTOP.height);
});
@@ -71,6 +75,46 @@ describe('ChatForm single row', () => {
expect(isSingleRow()).toBe(true);
});
+ it('keeps one line on the actions row when the page font is large', async () => {
+ await page.viewport(DESKTOP.width, DESKTOP.height);
+ document.documentElement.style.fontSize = '24px';
+
+ const { isSingleRow, write } = await renderForm();
+
+ await nextLayout();
+ expect(isSingleRow()).toBe(true);
+
+ await write('What is the meaning of life?');
+ expect(isSingleRow()).toBe(true);
+ });
+
+ it('takes the two rows when the placeholder of an empty form wraps', async () => {
+ await page.viewport(DESKTOP.width, DESKTOP.height);
+ document.body.style.width = '4rem';
+
+ const { isSingleRow } = await renderForm();
+
+ await nextLayout();
+ expect(isSingleRow()).toBe(false);
+ });
+
+ it('tries the one row again once a form that wrapped while empty is emptied', async () => {
+ await page.viewport(DESKTOP.width, DESKTOP.height);
+ document.body.style.width = '4rem';
+
+ const { isSingleRow, write } = await renderForm();
+
+ await nextLayout();
+ expect(isSingleRow()).toBe(false);
+
+ document.body.style.width = '';
+ await write('short');
+ expect(isSingleRow()).toBe(false);
+
+ await write('');
+ expect(isSingleRow()).toBe(true);
+ });
+
it('keeps the two rows on a phone', async () => {
await page.viewport(PHONE.width, PHONE.height);