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 Images, Video and Hub search typing responsive (#15306)

Daniel Han9e1ddce97f6c
diff --git a/.github/workflows/studio-composer-compatibility.yml b/.github/workflows/studio-composer-compatibility.yml
index c9a263894b6..70e97032eaa 100644
--- a/.github/workflows/studio-composer-compatibility.yml
+++ b/.github/workflows/studio-composer-compatibility.yml
@@ -188,6 +188,8 @@ jobs:
# before being wired in, so this adds coverage and not a new red.
run_driver "temp/queue-validation/compatibility/$browser-queue-localization.log" \
python tests/studio/playwright_queue_localization.py || status=1
+ run_driver "temp/queue-validation/compatibility/$browser-deferred-prompt.log" \
+ python tests/studio/playwright_composer_deferred_prompt.py || status=1
done
exit "$status"
- name: Native Safari simulations
diff --git a/studio/frontend/smoke-deferred-prompt-main.tsx b/studio/frontend/smoke-deferred-prompt-main.tsx
new file mode 100644
index 00000000000..782baf4e859
--- /dev/null
+++ b/studio/frontend/smoke-deferred-prompt-main.tsx
@@ -0,0 +1,68 @@
+// 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 { DeferredTextarea } from "@/components/deferred-textarea";
+// DeferredTextarea under a deliberately slow, impure owner (the Images page in WebKitGTK). No backend.
+/* eslint-disable react-hooks/purity, react-hooks/immutability, react-refresh/only-export-components */
+import { useState } from "react";
+import { createRoot } from "react-dom/client";
+import "./src/index.css";
+
+const SLOW_MS = Number(new URLSearchParams(location.search).get("slow") ?? 40);
+
+declare global {
+ interface Window {
+ ownerRenders: number;
+ ownerRendersInKey: number;
+ }
+}
+window.ownerRenders = 0;
+window.ownerRendersInKey = 0;
+// Brackets each keystroke's input dispatch: the first listener to see it and the last.
+let inKey = false;
+document.addEventListener(
+ "input",
+ () => {
+ inKey = true;
+ },
+ true,
+);
+window.addEventListener("input", () => {
+ inKey = false;
+});
+
+function Owner() {
+ const [prompt, setPrompt] = useState("seed prompt");
+ const [generated, setGenerated] = useState<string[]>([]);
+ window.ownerRenders += 1;
+ if (inKey) window.ownerRendersInKey += 1;
+ const until = performance.now() + SLOW_MS;
+ while (performance.now() < until) {
+ }
+ return (
+ <div className="flex max-w-xl flex-col gap-3 p-6">
+ <DeferredTextarea
+ aria-label="Instruction"
+ value={prompt}
+ onValueChange={setPrompt}
+ />
+ <output aria-label="Owner prompt">{prompt}</output>
+ <button type="button" onClick={() => setGenerated((g) => [...g, prompt])}>
+ Generate
+ </button>
+ <button type="button" onClick={() => setPrompt("from recall")}>
+ Recall
+ </button>
+ <button
+ type="button"
+ onClick={() => setPrompt((p) => `${p}, transparent background`)}
+ >
+ Append
+ </button>
+ <output aria-label="Generated">{JSON.stringify(generated)}</output>
+ </div>
+ );
+}
+
+const root = document.getElementById("root");
+if (root) createRoot(root).render(<Owner />);
diff --git a/studio/frontend/smoke-deferred-prompt.html b/studio/frontend/smoke-deferred-prompt.html
new file mode 100644
index 00000000000..c6ea722aa9c
--- /dev/null
+++ b/studio/frontend/smoke-deferred-prompt.html
@@ -0,0 +1,2 @@
+<!doctype html>
+<html lang="en"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Deferred prompt smoke test</title></head><body><div id="root"></div><script src="/crypto-boot.js"></script><script type="module" src="/smoke-deferred-prompt-main.tsx"></script></body></html>
diff --git a/studio/frontend/src/components/deferred-textarea.tsx b/studio/frontend/src/components/deferred-textarea.tsx
new file mode 100644
index 00000000000..535329b02f4
--- /dev/null
+++ b/studio/frontend/src/components/deferred-textarea.tsx
@@ -0,0 +1,49 @@
+// 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 { Textarea } from "@/components/ui/textarea";
+import { type ComponentProps, startTransition, useState } from "react";
+
+type DeferredTextareaProps = Omit<
+ ComponentProps<typeof Textarea>,
+ "value" | "onChange"
+> & {
+ value: string;
+ onValueChange: (value: string) => void;
+};
+
+/** Echoes keys itself and hands them to the owner as a transition, so a slow owner render yields to the next key (#15221). */
+export function DeferredTextarea({
+ value,
+ onValueChange,
+ onBlur,
+ ...props
+}: DeferredTextareaProps) {
+ const [draft, setDraft] = useState(value);
+ const [seen, setSeen] = useState(value);
+ // A value the owner set itself (recall, caption, buttons) replaces the draft; our own echo already matches.
+ if (value !== seen) {
+ setSeen(value);
+ if (value !== draft) {
+ setDraft(value);
+ }
+ }
+ return (
+ <Textarea
+ {...props}
+ value={draft}
+ onChange={(e) => {
+ const next = e.target.value;
+ setDraft(next);
+ startTransition(() => onValueChange(next));
+ }}
+ onBlur={(e) => {
+ // Blur is a discrete event, so this lands before a Generate click reads a still-pending transition.
+ if (draft !== value) {
+ onValueChange(draft);
+ }
+ onBlur?.(e);
+ }}
+ />
+ );
+}
diff --git a/studio/frontend/src/features/hub/hub-page.tsx b/studio/frontend/src/features/hub/hub-page.tsx
index 31a01cb719b..d47a82fec26 100644
--- a/studio/frontend/src/features/hub/hub-page.tsx
+++ b/studio/frontend/src/features/hub/hub-page.tsx
@@ -1545,7 +1545,9 @@ export function ModelsPage() {
// A new search starts on every uploader (Unsloth's still listed first), whatever was picked.
setUploaderPick(null);
}
- if (urlModel || urlSection) {
+ // Clearing the split view's auto-picked preview only re-picks it: 2 navigations per key (#15221).
+ const openedModel = !!urlModel && urlModel !== autoPreviewIdRef.current;
+ if (openedModel || urlSection) {
void navigate({
to: "/hub",
search: (prev) => ({
diff --git a/studio/frontend/src/features/images/images-page.tsx b/studio/frontend/src/features/images/images-page.tsx
index d3db0058b15..fd380e93b42 100644
--- a/studio/frontend/src/features/images/images-page.tsx
+++ b/studio/frontend/src/features/images/images-page.tsx
@@ -76,6 +76,7 @@ import { Slider } from "@/components/ui/slider";
import { useSidebar } from "@/components/ui/sidebar";
import { Spinner } from "@/components/ui/spinner";
import { Switch } from "@/components/ui/switch";
+import { DeferredTextarea } from "@/components/deferred-textarea";
import { Textarea } from "@/components/ui/textarea";
import {
Tooltip,
@@ -6904,7 +6905,7 @@ export function ImagesPage({
label={workflow === "edit" ? "Instruction" : "Prompt"}
hint={external ? undefined : status?.prompt_hint || undefined}
>
- <Textarea
+ <DeferredTextarea
data-type-to-activate="prompt"
rows={4}
className={cn(PROMPT_BOX_CLASS, "min-h-32")}
@@ -6917,7 +6918,7 @@ export function ImagesPage({
dismissExample(`images:${workflow}`);
setExamplesDismissed((prev) => ({ ...prev, [workflow]: true }));
}}
- onChange={(e) => setPrompt(e.target.value)}
+ onValueChange={setPrompt}
onPaste={(e) => {
// A whole AUTOMATIC1111 / Forge / Civitai block fills the form instead of the prompt.
const text = e.clipboardData.getData("text/plain");
@@ -7449,7 +7450,7 @@ export function ImagesPage({
alt="Live preview of the image being generated"
data-testid="images-live-preview"
style={{ maxWidth: width, maxHeight: height }}
- className="size-full object-contain shadow-sm"
+ className="media-stage-shadow size-full object-contain shadow-sm"
/>
) : selected && selectedSrc ? (
<>
@@ -7467,7 +7468,7 @@ export function ImagesPage({
openViewer();
}
}}
- className="max-h-full max-w-full cursor-zoom-in object-contain shadow-sm"
+ className="media-stage-shadow max-h-full max-w-full cursor-zoom-in object-contain shadow-sm"
/>
{/* Actions grouped in one glass toolbar so they stay legible over any image. Size and seed
live in the Recipe popover. */}
diff --git a/studio/frontend/src/features/video/video-page.tsx b/studio/frontend/src/features/video/video-page.tsx
index 59b0acdce69..48269099a6a 100644
--- a/studio/frontend/src/features/video/video-page.tsx
+++ b/studio/frontend/src/features/video/video-page.tsx
@@ -101,6 +101,7 @@ import {
SelectValue,
} from "@/components/ui/select";
import { Spinner } from "@/components/ui/spinner";
+import { DeferredTextarea } from "@/components/deferred-textarea";
import { Textarea } from "@/components/ui/textarea";
import {
Tooltip,
@@ -4086,7 +4087,7 @@ function VideoGenerator({
</div>
<Field label="Prompt" hint={status?.prompt_hint || undefined}>
- <Textarea
+ <DeferredTextarea
data-type-to-activate="prompt"
rows={4}
className={cn(PROMPT_BOX_CLASS, "min-h-32")}
@@ -4097,7 +4098,7 @@ function VideoGenerator({
dismissExample("video");
setExampleDismissed(true);
}}
- onChange={(e) => setPrompt(e.target.value)}
+ onValueChange={setPrompt}
/>
</Field>
{status?.supports_cfg !== false && (
@@ -4730,7 +4731,7 @@ function VideoGenerator({
alt="Live preview of the first frame being generated"
data-testid="video-live-preview"
style={livePreviewBox}
- className="size-full object-contain shadow-sm"
+ className="media-stage-shadow size-full object-contain shadow-sm"
/>
) : selected && selectedSrc ? (
<>
@@ -4756,7 +4757,7 @@ function VideoGenerator({
}
}}
onError={() => remintSrc(selected)}
- className="max-h-full max-w-full object-contain shadow-sm"
+ className="media-stage-shadow max-h-full max-w-full object-contain shadow-sm"
/>
{selected.has_audio && (
<div className="absolute left-4 top-4 flex items-center gap-1 rounded-full bg-background/80 px-2 py-1 text-ui-11 font-medium shadow-lg ring-1 ring-border backdrop-blur">
diff --git a/studio/frontend/src/index.css b/studio/frontend/src/index.css
index fe02056aea5..2d7ebd068e5 100644
--- a/studio/frontend/src/index.css
+++ b/studio/frontend/src/index.css
@@ -2014,6 +2014,11 @@ html.dark.render-linux:not(.no-font-smoothing):not([data-chat-font]):not([data-u
letter-spacing: 0.023em;
}
+/* WebKitGTK repaints the whole view per keystroke; this blurred shadow made each repaint ~150 ms (#15221). */
+html.tauri.render-linux .media-stage-shadow {
+ box-shadow: none;
+}
+
/* Chat font: only applies while a custom chat font is set. Elements with
explicit font utilities (headings, code) keep their own families. */
html[data-chat-font] .aui-root {
diff --git a/studio/frontend/tests/hub-search-keeps-auto-preview.test.ts b/studio/frontend/tests/hub-search-keeps-auto-preview.test.ts
new file mode 100644
index 00000000000..08e23212ca1
--- /dev/null
+++ b/studio/frontend/tests/hub-search-keeps-auto-preview.test.ts
@@ -0,0 +1,19 @@
+// 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 test from "node:test";
+import { readSrc } from "./helpers/kit.ts";
+
+test("typing a Hub search clears an opened model but not the split view's auto-picked preview", () => {
+ const src = readSrc("features/hub/hub-page.tsx");
+ const at = src.indexOf("const handleQueryChange");
+ assert.ok(at > 0);
+ const handler = src.slice(at, src.indexOf("setQuery(next);", at));
+ assert.match(
+ handler,
+ /const openedModel =\s*!!urlModel && urlModel !== autoPreviewIdRef\.current;/,
+ );
+ assert.match(handler, /if \(openedModel \|\| urlSection\) \{/);
+ assert.match(src, /autoPreviewIdRef\.current = firstId;/);
+});
diff --git a/studio/frontend/tests/media-stage-shadow.test.ts b/studio/frontend/tests/media-stage-shadow.test.ts
new file mode 100644
index 00000000000..e1a28f322b2
--- /dev/null
+++ b/studio/frontend/tests/media-stage-shadow.test.ts
@@ -0,0 +1,48 @@
+// 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 test from "node:test";
+import { readSrc } from "./helpers/kit.ts";
+
+test("only the Linux desktop app drops the full-size media shadow", () => {
+ const css = readSrc("index.css");
+ const rules = [
+ ...css.matchAll(/([^{}]*\.media-stage-shadow[^{}]*)\{([^}]*)\}/g),
+ ];
+ assert.equal(rules.length, 1);
+ assert.equal(
+ rules[0][1].trim().split("\n").pop()?.trim(),
+ "html.tauri.render-linux .media-stage-shadow",
+ );
+ assert.equal(rules[0][2].trim(), "box-shadow: none;");
+});
+
+test("every full-size media element with a shadow on Images and Video opts in", () => {
+ for (const file of [
+ "features/images/images-page.tsx",
+ "features/video/video-page.tsx",
+ ]) {
+ const src = readSrc(file);
+ const shadowed = [
+ ...src.matchAll(/className="([^"]*object-contain[^"]*shadow-sm[^"]*)"/g),
+ ];
+ assert.equal(shadowed.length, 2, file);
+ for (const [, cls] of shadowed)
+ assert.match(cls, /\bmedia-stage-shadow\b/, `${file}: ${cls}`);
+ }
+});
+
+test("the Images and Video prompt boxes hand keystrokes to the page as a transition", () => {
+ for (const file of [
+ "features/images/images-page.tsx",
+ "features/video/video-page.tsx",
+ ]) {
+ const src = readSrc(file);
+ const at = src.indexOf('data-type-to-activate="prompt"');
+ assert.match(src.slice(at - 40, at), /<DeferredTextarea\s*$/, file);
+ assert.match(src, /onValueChange=\{setPrompt\}/, file);
+ }
+ const component = readSrc("components/deferred-textarea.tsx");
+ assert.match(component, /startTransition\(\(\) => onValueChange\(next\)\)/);
+});
diff --git a/studio/frontend/tsconfig.app.json b/studio/frontend/tsconfig.app.json
index b8cbd170074..de5b9ca4a4d 100644
--- a/studio/frontend/tsconfig.app.json
+++ b/studio/frontend/tsconfig.app.json
@@ -46,6 +46,7 @@
"smoke-stream-pacing-main.tsx",
"smoke-code-block-flicker-main.tsx",
"smoke-tool-activity-main.tsx",
- "smoke-reasoning-transcript-main.tsx"
+ "smoke-reasoning-transcript-main.tsx",
+ "smoke-deferred-prompt-main.tsx"
]
}
diff --git a/tests/studio/playwright_composer_deferred_prompt.py b/tests/studio/playwright_composer_deferred_prompt.py
new file mode 100644
index 00000000000..c1de4b81546
--- /dev/null
+++ b/tests/studio/playwright_composer_deferred_prompt.py
@@ -0,0 +1,89 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+"""DeferredTextarea (the Images prompt box) under a slow owner; PW_ENGINE picks the browser engine (#15221)."""
+
+import json
+import os
+
+from playwright.sync_api import expect, sync_playwright
+from _playwright_robust import start_vite, stop_process, wait_for_smoke_page
+
+PAGE = "/smoke-deferred-prompt.html"
+ENTRY = "/smoke-deferred-prompt-main.tsx"
+TYPED = " with a small red boat near the shore"
+
+
+def check(page):
+ box = page.get_by_role("textbox", name = "Instruction", exact = True)
+ owner = page.get_by_label("Owner prompt")
+ generated = page.get_by_label("Generated")
+ expect(box).to_have_value("seed prompt")
+
+ # The slow owner must never render inside a key's input event.
+ box.click()
+ box.press("End")
+ box.press_sequentially(TYPED)
+ expect(box).to_have_value("seed prompt" + TYPED)
+ expect(owner).to_have_text("seed prompt" + TYPED)
+ in_key = page.evaluate("window.ownerRendersInKey")
+ assert in_key == 0, f"the owner rendered inside {in_key} of {len(TYPED)} keystrokes"
+
+ # A Generate pressed right after the last key reads the full text, not a pending transition.
+ box.press_sequentially(" now")
+ page.get_by_role("button", name = "Generate", exact = True).click()
+ expect(generated).to_have_text(
+ json.dumps(["seed prompt" + TYPED + " now"], separators = (",", ":"))
+ )
+
+ page.get_by_role("button", name = "Recall", exact = True).click()
+ expect(box).to_have_value("from recall")
+ page.get_by_role("button", name = "Append", exact = True).click()
+ expect(box).to_have_value("from recall, transparent background")
+
+ box.click()
+ box.press("End")
+ box.press_sequentially("!")
+ expect(owner).to_have_text("from recall, transparent background!")
+
+
+def main():
+ server = None
+ try:
+ base = os.environ.get("BASE_URL")
+ if not base:
+ port = int(os.environ.get("PW_PORT", "5423"))
+ server = start_vite(port)
+ base = f"http://127.0.0.1:{port}"
+ wait_for_smoke_page(base + PAGE, ENTRY, proc = server)
+ with sync_playwright() as pw:
+ options = {"headless": True}
+ if os.environ.get("PW_EXECUTABLE"):
+ options["executable_path"] = os.environ["PW_EXECUTABLE"]
+ if os.environ.get("PW_CHANNEL"):
+ options["channel"] = os.environ["PW_CHANNEL"]
+ browser = getattr(pw, os.environ.get("PW_ENGINE", "chromium")).launch(**options)
+ print(
+ f"Browser: {os.environ.get('PW_CHANNEL', os.environ.get('PW_ENGINE', 'chromium'))} {browser.version}",
+ flush = True,
+ )
+ try:
+ page = browser.new_page(viewport = {"width": 900, "height": 700})
+ errors = []
+ page.on("pageerror", lambda error: errors.append(str(error)))
+ page.goto(base + PAGE)
+ page.get_by_role("textbox", name = "Instruction", exact = True).wait_for(
+ state = "visible", timeout = 60_000
+ )
+ check(page)
+ assert not errors, errors
+ print("deferred prompt: OK", flush = True)
+ finally:
+ browser.close()
+ finally:
+ if server:
+ stop_process(server)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/tests/studio/test_browser_simulations_retry_once.py b/tests/studio/test_browser_simulations_retry_once.py
index 11f300a505f..586f6d97485 100644
--- a/tests/studio/test_browser_simulations_retry_once.py
+++ b/tests/studio/test_browser_simulations_retry_once.py
@@ -21,6 +21,7 @@ DRIVERS = (
"playwright_prompt_queue_actions.py",
"playwright_composer_settings.py",
"playwright_queue_localization.py",
+ "playwright_composer_deferred_prompt.py",
)