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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: switch light and dark without starting a transition on every element under Reduce motion (#16977)
Leo Borcherdinge2cdba5836bf
diff --git a/studio/frontend/src/features/settings/stores/theme-store.ts b/studio/frontend/src/features/settings/stores/theme-store.tsindex e7e73151815..bc892b7a65f 100644--- a/studio/frontend/src/features/settings/stores/theme-store.ts+++ b/studio/frontend/src/features/settings/stores/theme-store.ts@@ -70,23 +70,57 @@ function resolveTheme(theme: Theme): ResolvedTheme {return theme;}+export const THEME_SWITCHING_CLASS = "theme-switching";++// Mirrors the two index.css reduced-motion blocks.+function reducedMotionActive(el: HTMLElement): boolean {+ if (el.classList.contains("force-reduced-motion")) return true;+ if (el.classList.contains("force-motion")) return false;+ return (+ window.matchMedia?.("(prefers-reduced-motion: reduce)").matches === true+ );+}++// Reduce motion's 0.01ms `all` transition starts one per element per colour on a flip; otherwise the extra restyle costs WebKit more.+export function withoutTransitions(change: () => void): void {+ const el = document.documentElement;+ if (!reducedMotionActive(el)) {+ change();+ return;+ }+ el.classList.add(THEME_SWITCHING_CLASS);+ change();+ void window.getComputedStyle(document.body ?? el).color;+ window.setTimeout(() => el.classList.remove(THEME_SWITCHING_CLASS), 0);+}+function applyToDocument(resolved: ResolvedTheme) {if (typeof document === "undefined") return;const el = document.documentElement;- el.classList.toggle("dark", resolved === "dark");- el.classList.toggle("light", resolved === "light");- el.style.colorScheme = resolved;+ if (+ el.classList.contains("dark") === (resolved === "dark") &&+ el.classList.contains("light") === (resolved === "light")+ ) {+ el.style.colorScheme = resolved;+ return;+ }+ withoutTransitions(() => {+ el.classList.toggle("dark", resolved === "dark");+ el.classList.toggle("light", resolved === "light");+ el.style.colorScheme = resolved;+ });}function applyPaletteToDocument(palette: Palette) {if (typeof document === "undefined") return;const el = document.documentElement;// Standard is the base :root/.dark palette and uses no attribute.- if (palette === "standard") {- el.removeAttribute("data-palette");- } else {- el.setAttribute("data-palette", palette);- }+ const next = palette === "standard" ? null : palette;+ if (el.getAttribute("data-palette") === next) return;+ withoutTransitions(() => {+ if (next === null) el.removeAttribute("data-palette");+ else el.setAttribute("data-palette", next);+ });}const listeners = new Set<() => void>();diff --git a/studio/frontend/src/index.css b/studio/frontend/src/index.cssindex c2180e21901..33a6a13eea7 100644--- a/studio/frontend/src/index.css+++ b/studio/frontend/src/index.css@@ -1810,6 +1810,13 @@ html.force-reduced-motion [data-radix-popper-content-wrapper] {transition-property: none !important;}+/* theme-store.ts withoutTransitions: :root outranks both reduced-motion blocks. */+:root.theme-switching *,+:root.theme-switching *::before,+:root.theme-switching *::after {+ transition: none !important;+}+/* Same loader exceptions as the OS-level media block below: freezingspinners removes the only signal that work is in flight. */html.force-reduced-motion .animate-spin {diff --git a/studio/frontend/tests/theme-switch-without-transitions.test.ts b/studio/frontend/tests/theme-switch-without-transitions.test.tsnew file mode 100644index 00000000000..d7f1c4770e5--- /dev/null+++ b/studio/frontend/tests/theme-switch-without-transitions.test.ts@@ -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++import assert from "node:assert/strict";+import test from "node:test";++import { readSrc } from "./helpers/kit.ts";++type Timer = () => void;++function fakeDom(reduceMotion: boolean) {+ const classes = new Set<string>(["light"]);+ if (reduceMotion) classes.add("force-reduced-motion");+ const attrs = new Map<string, string>();+ const log: string[] = [];+ const timers: Timer[] = [];+ const root = {+ classList: {+ add: (c: string) => classes.add(c),+ remove: (c: string) => classes.delete(c),+ contains: (c: string) => classes.has(c),+ toggle: (c: string, on: boolean) => {+ if (on !== classes.has(c)) log.push(`${on ? "+" : "-"}${c}`);+ if (on) classes.add(c);+ else classes.delete(c);+ },+ },+ style: { colorScheme: "light" },+ getAttribute: (n: string) => attrs.get(n) ?? null,+ setAttribute: (n: string, v: string) => {+ log.push(`${n}=${v}`);+ attrs.set(n, v);+ },+ removeAttribute: (n: string) => {+ log.push(`-${n}`);+ attrs.delete(n);+ },+ };+ const g = globalThis as Record<string, unknown>;+ g.document = { documentElement: root, body: {} };+ g.localStorage = { getItem: () => null, setItem: () => {} };+ g.window = {+ localStorage: g.localStorage,+ matchMedia: () => ({ matches: false, addEventListener() {}, removeEventListener() {} }),+ addEventListener() {},+ removeEventListener() {},+ getComputedStyle: () => {+ log.push(`flush(switching=${classes.has("theme-switching")})`);+ return { color: "" };+ },+ setTimeout: (fn: Timer) => {+ timers.push(fn);+ return 0;+ },+ };+ return { classes, log, timers };+}++test("under Reduce motion a light/dark flip commits the new colours with transitions off, then turns them back on", async () => {+ const dom = fakeDom(true);+ const store = await import("../src/features/settings/stores/theme-store.ts");++ store.setTheme("dark");+ assert.deepEqual(dom.log, ["+dark", "-light", "flush(switching=true)"]);+ assert.ok(dom.classes.has("theme-switching"), "transitions stay off until the queued task");+ dom.timers.splice(0).forEach((fn) => fn());+ assert.ok(!dom.classes.has("theme-switching"));++ dom.log.length = 0;+ store.setTheme("dark");+ assert.deepEqual(dom.log, [], "re-applying the same theme forces no style flush");++ store.setPalette("standard");+ assert.deepEqual(dom.log, [], "the standard palette is already the attribute-free default");++ dom.classes.delete("force-reduced-motion");+ store.setTheme("light");+ assert.deepEqual(dom.log, ["-dark", "+light"], "without Reduce motion the flip keeps main's path");+ assert.equal(dom.timers.length, 0);+});++test("the switching rule outranks both reduced-motion blocks", () => {+ const css = readSrc("index.css");+ assert.match(+ css,+ /:root\.theme-switching \*,\s*:root\.theme-switching \*::before,\s*:root\.theme-switching \*::after \{\s*transition: none !important;\s*\}/,+ ":root plus a class (0,2,0) beats html.force-reduced-motion * and html:not(.force-motion) * (0,1,1), which give every element a 0.01ms `all` transition",+ );+});