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: stop the macOS desktop app typing stray control characters for unhandled keys (#14815)

Debojyoti Banerjee394aff854539
diff --git a/studio/frontend/scripts/check-bundle-budget.ts b/studio/frontend/scripts/check-bundle-budget.ts
index 93c70eed59f..598f4a3977b 100644
--- a/studio/frontend/scripts/check-bundle-budget.ts
+++ b/studio/frontend/scripts/check-bundle-budget.ts
@@ -401,8 +401,11 @@ export const BUDGET = {
// Hub metadata caching and hidden-row filtering (#14265): +548 B raw / +146 B transfer (6,925,639 ->
// 6,926,187 B raw, 2,086,290 -> 2,086,436 B transfer against 0ee5cfc58, Node 24, 98 chunks), where main
// was already over the line above. Set to the merged build plus about 200 B.
- transferBytes: 2_086_630,
- rawBytes: 6_926_390,
+ // macOS Desktop stray key text guard (#14815), eager in main.tsx: +278 B raw / +114 B transfer
+ // (6,925,639 -> 6,925,917 B raw, 2,086,290 -> 2,086,404 B transfer against 14e0178e0, Node 24, chunk count
+ // unchanged at 98). Raised by +278 B raw / +129 B transfer so main's margin stays where it was.
+ transferBytes: 2_086_759,
+ rawBytes: 6_926_668,
};
// The chunk count is reported but not budgeted. Splitting a page out of the entry raises it while lowering the
diff --git a/studio/frontend/src/lib/mac-stray-key-text.ts b/studio/frontend/src/lib/mac-stray-key-text.ts
new file mode 100644
index 00000000000..94e9ca33fb7
--- /dev/null
+++ b/studio/frontend/src/lib/mac-stray-key-text.ts
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+// The macOS app's child webview (Tauri `unstable`) re-sends a key the page leaves unhandled to the
+// window, whose text input then types its control character into the field: U+001C left at the
+// start, U+001D right at the end, U+0001 Home, U+0004 End (#14764, tauri-apps/tauri#10194). No key
+// types C0 controls or DEL on purpose; tab, line feed and carriage return are kept.
+// biome-ignore lint/suspicious/noControlCharactersInRegex: control characters are what this finds
+const STRAY_KEY_TEXT = /^[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]+$/;
+
+export function isStrayKeyText(
+ inputType: string,
+ data: string | null,
+): boolean {
+ return (
+ inputType === "insertText" &&
+ typeof data === "string" &&
+ STRAY_KEY_TEXT.test(data)
+ );
+}
+
+export function watchMacStrayKeyText(win: Window): void {
+ win.addEventListener(
+ "beforeinput",
+ (event) => {
+ if (isStrayKeyText(event.inputType, event.data)) {
+ event.preventDefault();
+ }
+ },
+ true,
+ );
+}
diff --git a/studio/frontend/src/main.tsx b/studio/frontend/src/main.tsx
index 963a7e67bfe..716bf0ef934 100644
--- a/studio/frontend/src/main.tsx
+++ b/studio/frontend/src/main.tsx
@@ -28,6 +28,7 @@ import { initializeLocale } from "./i18n";
import { isTauri } from "./lib/api-base";
import { setHubSessionRefresh } from "./lib/hf-endpoint";
import { watchInputModality } from "./lib/input-modality";
+import { watchMacStrayKeyText } from "./lib/mac-stray-key-text";
import { watchOverlayScrollbarGutter } from "./lib/overlay-scrollbar";
import { watchSpellCheck } from "./lib/spellcheck";
@@ -76,6 +77,11 @@ watchInputModality(window);
// Before the first render, so a disabled spell check never flashes underlines.
watchSpellCheck(window);
+// The macOS app types a control character for a key the page leaves unhandled (#14764).
+if (isTauri && /Mac/.test(navigator.platform)) {
+ watchMacStrayKeyText(window);
+}
+
function renderApp(): void {
root.render(
<StrictMode>
diff --git a/studio/frontend/tests/mac-stray-key-text.test.ts b/studio/frontend/tests/mac-stray-key-text.test.ts
new file mode 100644
index 00000000000..433c41ee945
--- /dev/null
+++ b/studio/frontend/tests/mac-stray-key-text.test.ts
@@ -0,0 +1,107 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import assert from "node:assert/strict";
+import { readFile } from "node:fs/promises";
+import test from "node:test";
+
+import {
+ isStrayKeyText,
+ watchMacStrayKeyText,
+} from "../src/lib/mac-stray-key-text.ts";
+
+const MAIN = await readFile(
+ new URL("../src/main.tsx", import.meta.url),
+ "utf8",
+);
+
+test("the control characters macOS types for unhandled keys are stray", () => {
+ // Left, right, Home, End (seen on macOS 15 and 26), then up, down and DEL.
+ for (const data of [
+ "\u001c",
+ "\u001d",
+ "\u0001",
+ "\u0004",
+ "\u001e",
+ "\u001f",
+ "\u007f",
+ ]) {
+ assert.equal(
+ isStrayKeyText("insertText", data),
+ true,
+ JSON.stringify(data),
+ );
+ }
+ assert.equal(isStrayKeyText("insertText", "\u001c\u001c"), true);
+});
+
+test("typed text, tabs and line breaks are kept", () => {
+ for (const data of [
+ "a",
+ " ",
+ "é",
+ "\uf8ff",
+ "\t",
+ "\n",
+ "\r",
+ "a\u001c",
+ "日本",
+ ]) {
+ assert.equal(
+ isStrayKeyText("insertText", data),
+ false,
+ JSON.stringify(data),
+ );
+ }
+ assert.equal(isStrayKeyText("insertText", ""), false);
+ assert.equal(isStrayKeyText("insertText", null), false);
+});
+
+test("only plain typing is filtered, never paste, drop or deletion", () => {
+ for (const inputType of [
+ "insertFromPaste",
+ "insertFromDrop",
+ "insertReplacementText",
+ "insertCompositionText",
+ "deleteContentBackward",
+ ]) {
+ assert.equal(isStrayKeyText(inputType, "\u001c"), false, inputType);
+ }
+});
+
+test("the guard cancels a stray insertion before any other listener sees it", () => {
+ type Registration = [string, (event: InputEvent) => void, unknown];
+ const registered: Registration[] = [];
+ const win = {
+ addEventListener: (...args: Registration) => {
+ registered.push(args);
+ },
+ } as unknown as Window;
+ watchMacStrayKeyText(win);
+ assert.equal(registered.length, 1);
+ const [type, listener, capture] = registered[0];
+ assert.equal(type, "beforeinput");
+ assert.equal(capture, true);
+
+ const send = (inputType: string, data: string | null) => {
+ let prevented = false;
+ listener({
+ inputType,
+ data,
+ preventDefault: () => {
+ prevented = true;
+ },
+ } as unknown as InputEvent);
+ return prevented;
+ };
+ assert.equal(send("insertText", "\u001c"), true);
+ assert.equal(send("insertText", "x"), false);
+ assert.equal(send("insertFromPaste", "\u001c"), false);
+});
+
+test("the guard is installed only in the macOS desktop app", () => {
+ assert.match(
+ MAIN,
+ /if \(isTauri && \/Mac\/\.test\(navigator\.platform\)\) \{\s*watchMacStrayKeyText\(window\);/,
+ );
+});