Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: keep the chat composer typing after a send on WebKitGTK Wayland (#13222)

Daniel Hana89c7f561fc8
diff --git a/studio/frontend/src/components/assistant-ui/thread.tsx b/studio/frontend/src/components/assistant-ui/thread.tsx
index 460e2b34600..859f2f9b2a0 100644
--- a/studio/frontend/src/components/assistant-ui/thread.tsx
+++ b/studio/frontend/src/components/assistant-ui/thread.tsx
@@ -2794,7 +2794,7 @@ const Composer: FC<{
const setMentionOpen = useCallback((open: boolean) => {
mentionOpenRef.current = open;
}, []);
- const { inputProps, isComposing, isComposingRef } =
+ const { inputProps, isComposing, isComposingRef, imeSessionOpenRef } =
useImeComposerInputHandlers({
submitOnEnter: true,
skipEnterRef: mentionConsumesEnterRef,
@@ -3827,11 +3827,15 @@ const Composer: FC<{
}, [draftKey, pasteDraftKey]);
// Call wherever the composer is emptied because its text left as a message.
const armJustSent = useCallback((...texts: string[]) => {
- justSentRef.current = armSentTextGuard(texts, draftKeyRef.current);
+ justSentRef.current = armSentTextGuard(
+ texts,
+ draftKeyRef.current,
+ imeSessionOpenRef.current,
+ );
// Here, not beside send(): handleSubmit returns early on the three queueing
// paths, which empty the composer too.
setIsWritingExpanded(false);
- }, []);
+ }, [imeSessionOpenRef]);
const clearStoredDraft = useCallback(() => {
if (draftSaveTimerRef.current !== null) {
clearTimeout(draftSaveTimerRef.current);
@@ -5954,6 +5958,7 @@ function useImeComposerInputHandlers({
},
isComposing,
isComposingRef: composingRef,
+ imeSessionOpenRef,
};
}
diff --git a/studio/frontend/src/features/chat/utils/composer-send-guard.ts b/studio/frontend/src/features/chat/utils/composer-send-guard.ts
index abd71832b6e..8ffa02c320b 100644
--- a/studio/frontend/src/features/chat/utils/composer-send-guard.ts
+++ b/studio/frontend/src/features/chat/utils/composer-send-guard.ts
@@ -13,16 +13,21 @@ export type SentTextGuard = {
readonly draftKey: string | null;
/** A key has been pressed since the send. See markSentTextGuardUserInput. */
readonly userInputSince: boolean;
+ /** An IME composition was open at the send; if not, a composition write is typing (WebKitGTK
+ * on Wayland commits every keystroke as one, #10012). */
+ readonly compositionOpen: boolean;
};
export function armSentTextGuard(
texts: readonly string[],
draftKey: string | null,
+ compositionOpen = true,
): SentTextGuard {
return {
texts: texts.filter((text) => text.length > 0),
draftKey,
userInputSince: false,
+ compositionOpen,
};
}
@@ -88,6 +93,9 @@ export function applySentTextGuard(
): { accept: boolean; guard: SentTextGuard | null } {
if (guard === null) return { accept: true, guard: null };
if (write.isDeliberate) return { accept: true, guard: null };
+ if (write.isComposition && !guard.compositionOpen) {
+ return { accept: true, guard: null };
+ }
// Re-typing the whole prompt is only one write when it is one character, so equality alone
// would swallow every retry of a "?" or a single emoji.
if (guard.texts.includes(write.value)) {
diff --git a/studio/frontend/tests/composer-send-guard.test.ts b/studio/frontend/tests/composer-send-guard.test.ts
index 45cbe1cbc9f..2adb580b582 100644
--- a/studio/frontend/tests/composer-send-guard.test.ts
+++ b/studio/frontend/tests/composer-send-guard.test.ts
@@ -2,6 +2,7 @@
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
import assert from "node:assert/strict";
+import { readFileSync } from "node:fs";
import test from "node:test";
import {
@@ -45,6 +46,8 @@ const composing = (value: string) => ({
isComposition: true,
composerIsEmpty: true,
});
+const ARMS_WITH_IME_SESSION =
+ /armSentTextGuard\(\s*texts,\s*draftKeyRef\.current,\s*imeSessionOpenRef\.current,?\s*\)/;
const armed = (texts: string[] = [PROMPT], key: string | null = KEY) =>
armSentTextGuard(texts, key);
@@ -290,6 +293,37 @@ test("a composition begun after the send is applied", () => {
});
});
+test("a composition write with none open at the send is applied", () => {
+ const guard = armSentTextGuard([PROMPT], KEY, false);
+ for (const value of ["h", "\u65e5\u672c\u8a9e"]) {
+ assert.deepEqual(applySentTextGuard(guard, composing(value)), {
+ accept: true,
+ guard: null,
+ });
+ }
+});
+
+test("retyping a one-character prompt applies with no composition open at the send", () => {
+ const guard = armSentTextGuard(["?"], KEY, false);
+ assert.deepEqual(applySentTextGuard(guard, composing("?")), {
+ accept: true,
+ guard: null,
+ });
+});
+
+test("the sent text is still refused when typed by plain keys", () => {
+ const guard = armSentTextGuard([PROMPT], KEY, false);
+ assert.equal(applySentTextGuard(guard, typed(PROMPT)).accept, false);
+});
+
+test("the composer arms the guard with whether an IME session was open", () => {
+ const thread = readFileSync(
+ new URL("../src/components/assistant-ui/thread.tsx", import.meta.url),
+ "utf8",
+ );
+ assert.match(thread, ARMS_WITH_IME_SESSION);
+});
+
// AltGr is how a lot of layouts reach @, so a one-character prompt typed with
// it must retire the equality guard. Windows reports it as Ctrl+Alt, and some
// builds set those flags even while AltGraph reads true, so both forms count.