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: mark the root when the chat wallpaper is ready instead of html:has() (#16117)

Daniel Han1952d233dc4f
diff --git a/studio/frontend/src/features/chat-background/background.tsx b/studio/frontend/src/features/chat-background/background.tsx
index 7e8381c0ede..42c9d6113ee 100644
--- a/studio/frontend/src/features/chat-background/background.tsx
+++ b/studio/frontend/src/features/chat-background/background.tsx
@@ -12,6 +12,25 @@ import { safeArtworkOpacity, type RGB } from "./contrast";
import type { ChatBackgroundValue } from "./model";
type Frame = { url: string; value: ChatBackgroundValue };
+// The window titlebar sits outside the wallpaper's subtree, so a ready wallpaper marks the root
+// rather than having CSS ask html:has(), which re-matches on every DOM change.
+const ROOT_READY = "data-chat-wallpaper-ready";
+const ROOT_WORKSPACE_READY = "data-chat-wallpaper-workspace-ready";
+const rootMarks = new Map<string, number>();
+function markRoot(names: string[]): () => void {
+ const root = document.documentElement;
+ for (const name of names) {
+ rootMarks.set(name, (rootMarks.get(name) ?? 0) + 1);
+ root.setAttribute(name, "");
+ }
+ return () => {
+ for (const name of names) {
+ const left = (rootMarks.get(name) ?? 1) - 1;
+ rootMarks.set(name, left);
+ if (left <= 0) root.removeAttribute(name);
+ }
+ };
+}
export function ChatBackground({ active = true }: { active?: boolean }) {
const { value } = useChatBackground();
const enabled = Boolean(value);
@@ -162,6 +181,15 @@ export function ChatBackground({ active = true }: { active?: boolean }) {
},
[],
);
+ const shownReady = Boolean(value && active && frames.current);
+ useEffect(() => {
+ // Only the app's own wallpaper drives the titlebar; a settings preview never marks the root.
+ const parent = host.current?.parentElement;
+ if (!shownReady || !parent) return;
+ const workspace = parent.hasAttribute("data-wallpaper-workspace");
+ if (!workspace && !parent.hasAttribute("data-chat-content-root")) return;
+ return markRoot(workspace ? [ROOT_READY, ROOT_WORKSPACE_READY] : [ROOT_READY]);
+ }, [shownReady]);
if (!value || !active) return null;
return (
<div
diff --git a/studio/frontend/src/index.css b/studio/frontend/src/index.css
index 71c9b9dbaf4..b511fe1ca51 100644
--- a/studio/frontend/src/index.css
+++ b/studio/frontend/src/index.css
@@ -6762,22 +6762,22 @@ html.force-reduced-motion .spooky-still :is(.spooky-spider, .spooky-bat) {
background: linear-gradient(color-mix(in srgb, var(--background) 48%, transparent), transparent);
}
:is([data-wallpaper-workspace], [data-chat-content-root]):has(> .chat-wallpaper[data-ready]) [data-side-panel-inset]:not(.chat-header-fade),
-html:has(:is([data-wallpaper-workspace], [data-chat-content-root]) > .chat-wallpaper[data-ready]) [data-slot="window-titlebar"] {
+html[data-chat-wallpaper-ready] [data-slot="window-titlebar"] {
background: transparent;
backdrop-filter: none;
}
:is([data-wallpaper-workspace], [data-chat-content-root]):has(> .chat-wallpaper[data-ready]) .chat-header-fade,
-html:has(:is([data-wallpaper-workspace], [data-chat-content-root]) > .chat-wallpaper[data-ready]) [data-slot="window-titlebar-decoration"] {
+html[data-chat-wallpaper-ready] [data-slot="window-titlebar-decoration"] {
visibility: hidden;
}
:is([data-wallpaper-workspace], [data-chat-content-root]):has(> .chat-wallpaper[data-ready]) [data-wallpaper-chrome-controls],
-html:has(:is([data-wallpaper-workspace], [data-chat-content-root]) > .chat-wallpaper[data-ready]) [data-slot="window-titlebar"] [data-wallpaper-chrome-controls] {
+html[data-chat-wallpaper-ready] [data-slot="window-titlebar"] [data-wallpaper-chrome-controls] {
background: transparent;
backdrop-filter: none;
text-shadow: 0 1px 8px var(--background);
}
/* The pinned sidebar stays solid, including its segment of the native titlebar. */
-html:has([data-wallpaper-workspace] > .chat-wallpaper[data-ready]) [data-slot="window-titlebar"][data-wallpaper-sidebar-pinned] > [data-wallpaper-chrome-controls]:first-child {
+html[data-chat-wallpaper-workspace-ready] [data-slot="window-titlebar"][data-wallpaper-sidebar-pinned] > [data-wallpaper-chrome-controls]:first-child {
background: var(--sidebar);
}
/* One viewport-sized crop, so opening the sidebar does not reframe the image. */
diff --git a/studio/frontend/tests/titlebar-modal-layering.test.ts b/studio/frontend/tests/titlebar-modal-layering.test.ts
index f45742a4563..4a272222b2b 100644
--- a/studio/frontend/tests/titlebar-modal-layering.test.ts
+++ b/studio/frontend/tests/titlebar-modal-layering.test.ts
@@ -27,8 +27,9 @@ const TITLEBAR_BACKDROP_RULE_PATTERN =
/\[data-slot="window-titlebar"\]\[data-viewport-backdrop-open\]::after\s*\{\s*opacity:\s*1;\s*\}/;
const TITLEBAR_BACKDROP_STORE_PATTERN =
/useSyncExternalStore\(\s*enabled \? subscribeViewportBackdrop : subscribeNever,/;
+// On the titlebar's own opening tag; other attributes may sit between the two.
const TITLEBAR_BACKDROP_ATTRIBUTE_PATTERN =
- /data-slot="window-titlebar"\s+data-viewport-backdrop-open=\{backdropOpen \? "" : undefined\}/;
+ /data-slot="window-titlebar"[^>]*?\sdata-viewport-backdrop-open=\{backdropOpen \? "" : undefined\}/;
const TOUR_VIEWPORT_BACKDROP_PATTERN =
/data-slot="dialog-overlay"[\s\S]*?data-viewport-backdrop=\{true\}/;