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
Unsloth Studio / Desktop: stop spam-clicking sidebar rows from queueing a navigation per click (#12544)
Leo Borcherding8254e67f9eda
diff --git a/studio/frontend/src/components/app-sidebar.tsx b/studio/frontend/src/components/app-sidebar.tsxindex cbedcd7eb6a..9def173f2dc 100644--- a/studio/frontend/src/components/app-sidebar.tsx+++ b/studio/frontend/src/components/app-sidebar.tsx@@ -146,6 +146,7 @@ import { HugeiconsIcon, type IconSvgElement } from "@hugeicons/react";import { ArrowRightIcon, ChevronDown, GitBranchIcon, Moon } from "lucide-react";import {Link,+ type NavigateOptions,useNavigate,useRouter,useRouterState,@@ -234,6 +235,7 @@ import type {} from "@/features/settings";import { useEffectiveProfile, UserAvatar } from "@/features/profile";import { resolveNavRowState } from "@/components/nav-row-state";+import { createNavigationCoalescer } from "@/components/sidebar-navigation";import { fetchDeviceType, usePlatformStore } from "@/config/env";import { videoNavHint } from "@/config/hardware-verdict";import {@@ -899,6 +901,21 @@ export function AppSidebar() {} = useSidebar();const navigate = useNavigate();const router = useRouter();+ const [rowNavigation] = useState(() =>+ createNavigationCoalescer<NavigateOptions>({+ navigate: (options) => navigate(options),+ currentHref: () => router.latestLocation.href,+ hrefOf: (options) => router.buildLocation(options).href,+ currentEntry: () => router.latestLocation.state.__TSR_key,+ asReplace: (options) => ({ ...options, replace: true }),+ }),+ );+ const navigateFromRow = rowNavigation.go;+ useEffect(+ () =>+ router.subscribe("onResolved", () => rowNavigation.resolved()),+ [router, rowNavigation],+ );const imagesPageMode = useImageWorkflowStore((s) => s.pageMode);// `webUpdate` is non-null only when the installed (PyPI) version is behind the latest release.@@ -2536,7 +2553,7 @@ export function AppSidebar() {label: t("shell.navigation.projects"),active: pathname === "/projects" || pathname.startsWith("/projects/"),onClick: () => {- navigate({ to: "/projects" });+ navigateFromRow({ to: "/projects" });closeMobileIfOpen();},onIntent: () => {@@ -2571,7 +2588,7 @@ export function AppSidebar() {label: t("shell.navigation.library"),active: pathname === "/library",onClick: () => {- navigate({ to: "/library" });+ navigateFromRow({ to: "/library" });closeMobileIfOpen();},onIntent: () => {@@ -2583,7 +2600,7 @@ export function AppSidebar() {label: t("shell.navigation.hub"),active: pathname === "/hub" || pathname.startsWith("/hub/"),onClick: () => {- navigate({ to: "/hub" });+ navigateFromRow({ to: "/hub" });closeMobileIfOpen();},onIntent: () => {@@ -2596,7 +2613,7 @@ export function AppSidebar() {// No "New" pill: the row's trailing slot holds the workflow disclosure instead.active: pathname === "/images" || pathname.startsWith("/images/"),onClick: () => {- navigate({ to: "/images" });+ navigateFromRow({ to: "/images" });closeMobileIfOpen();},onIntent: () => {@@ -2614,7 +2631,7 @@ export function AppSidebar() {pendingTooltip: t("shell.navigation.trainChecking"),onClick: () => {if (chatOnlyMeasured) return;- navigate({ to: "/studio" });+ navigateFromRow({ to: "/studio" });closeMobileIfOpen();},onIntent: () => {@@ -2631,7 +2648,7 @@ export function AppSidebar() {pending: capabilitiesUnknown,pendingTooltip: t("shell.navigation.videoChecking"),onClick: () => {- navigate({ to: "/video" });+ navigateFromRow({ to: "/video" });closeMobileIfOpen();},onIntent: () => {@@ -2643,7 +2660,7 @@ export function AppSidebar() {label: t("shell.navigation.audio"),active: pathname === "/audio" || pathname.startsWith("/audio/"),onClick: () => {- navigate({ to: "/audio" });+ navigateFromRow({ to: "/audio" });closeMobileIfOpen();},onIntent: () => {@@ -2655,7 +2672,7 @@ export function AppSidebar() {label: t("shell.navigation.recipes"),active: isRecipesRoute,onClick: () => {- navigate({ to: "/data-recipes" });+ navigateFromRow({ to: "/data-recipes" });closeMobileIfOpen();},onIntent: () => {@@ -2673,7 +2690,7 @@ export function AppSidebar() {active: pathname === "/export" || pathname.startsWith("/export/"),spinner: exportInProgress,onClick: () => {- navigate({ to: "/export" });+ navigateFromRow({ to: "/export" });closeMobileIfOpen();},onIntent: () => {@@ -2691,7 +2708,7 @@ export function AppSidebar() {label: t("shell.navigation.api"),active: pathname === "/api-monitor" || pathname.startsWith("/api-monitor/"),onClick: () => {- navigate({ to: "/api-monitor" });+ navigateFromRow({ to: "/api-monitor" });closeMobileIfOpen();},onIntent: () => {@@ -3269,7 +3286,7 @@ export function AppSidebar() {clearSelection();clearChatNotifications(item);noteViewed(item.id);- navigate({+ navigateFromRow({to: "/chat",search:item.type === "single"diff --git a/studio/frontend/src/components/sidebar-navigation.ts b/studio/frontend/src/components/sidebar-navigation.tsnew file mode 100644index 00000000000..b187b83e1d3--- /dev/null+++ b/studio/frontend/src/components/sidebar-navigation.ts@@ -0,0 +1,39 @@+// 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-free so it is testable: app-sidebar.tsx pulls in the whole shell.++/**+ * Sidebar clicks: drop one on where the router is or is heading; while the entry the last+ * click pushed has not rendered, send the next at once as a replace, so the router cancels+ * the stale load and a burst leaves one history entry. Only that entry: Back/Forward onto a+ * slow page, or a navigation still held by a blocker (unsaved Library note), keeps its entry.+ */+export function createNavigationCoalescer<T>({+ navigate,+ currentHref,+ hrefOf,+ currentEntry,+ asReplace,+}: {+ navigate: (options: T) => Promise<unknown>;+ currentHref: () => string;+ hrefOf: (options: T) => string;+ currentEntry: () => string | undefined;+ asReplace: (options: T) => T;+}): { go: (options: T) => void; resolved: () => void } {+ let unshown: string | undefined;++ return {+ go(options: T) {+ if (hrefOf(options) === currentHref()) return;+ const replace = unshown !== undefined && currentEntry() === unshown;+ void navigate(replace ? asReplace(options) : options).catch(() => {});+ unshown = currentHref() === hrefOf(options) ? currentEntry() : undefined;+ },+ // The router resolves only when nothing is pending: the entry rendered or history left it.+ resolved() {+ unshown = undefined;+ },+ };+}diff --git a/studio/frontend/tests/sidebar-navigation-coalesce.test.ts b/studio/frontend/tests/sidebar-navigation-coalesce.test.tsnew file mode 100644index 00000000000..3a400c80ca7--- /dev/null+++ b/studio/frontend/tests/sidebar-navigation-coalesce.test.ts@@ -0,0 +1,140 @@+// 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 { readSrcAsync } from "./helpers/kit.ts";++const { createNavigationCoalescer } =+ await import("../src/components/sidebar-navigation.ts");++type Nav = { to: string; replace?: boolean };+type Entry = { href: string; key: string };++// A fake router over a history stack: push and replace mint a fresh key, as TanStack history+// does; `render()` resolves the current entry, as the router's onResolved does. With+// `blocked`, navigations wait on a blocker before touching history (the Library note save).+function fakeRouter(start = "/chat", { blocked = false } = {}) {+ let n = 0;+ const entry = (href: string): Entry => ({ href, key: `k${n++}` });+ const stack: Entry[] = [entry(start)];+ let index = 0;+ const calls: string[] = [];+ const nav = createNavigationCoalescer<Nav>({+ navigate: (o) => {+ calls.push(o.replace ? `replace ${o.to}` : o.to);+ if (!blocked) {+ if (o.replace) stack[index] = entry(o.to);+ else {+ stack.splice(index + 1, Infinity, entry(o.to));+ index += 1;+ }+ }+ return new Promise(() => {});+ },+ currentHref: () => stack[index].href,+ hrefOf: (o) => o.to,+ currentEntry: () => stack[index].key,+ asReplace: (o) => ({ ...o, replace: true }),+ });+ return {+ click: (to: string) => nav.go({ to }),+ render: () => nav.resolved(),+ back: () => {+ index -= 1;+ },+ forward: () => {+ index += 1;+ },+ hrefs: () => stack.map((e) => e.href),+ calls,+ };+}++test("a click on the current page does not navigate", () => {+ const r = fakeRouter("/library");+ r.click("/library");+ assert.deepEqual(r.calls, []);+});++test("clicking the row that is still loading does not start a second load", () => {+ const r = fakeRouter();+ r.click("/hub");+ r.click("/hub");+ assert.deepEqual(r.calls, ["/hub"]);+});++test("a click during a load goes out at once and replaces the unshown entry", () => {+ const r = fakeRouter();+ r.click("/hub");+ r.click("/library");+ r.click("/images");+ assert.deepEqual(r.calls, ["/hub", "replace /library", "replace /images"]);+ assert.deepEqual(r.hrefs(), ["/chat", "/images"]);+});++test("the next click after a load renders pushes a new entry", () => {+ const r = fakeRouter();+ r.click("/hub");+ r.render();+ r.click("/library");+ assert.deepEqual(r.hrefs(), ["/chat", "/hub", "/library"]);+});++test("a click while Back is still loading keeps the entry Back landed on", () => {+ const r = fakeRouter();+ r.click("/hub");+ r.render();+ r.click("/library");+ r.render();+ r.back();+ r.click("/images");+ assert.deepEqual(r.hrefs(), ["/chat", "/hub", "/images"]);+});++test("Back onto the entry a click pushed, once rendered, is not replaced", () => {+ const r = fakeRouter();+ r.click("/hub");+ r.render();+ r.click("/library");+ r.back();+ r.click("/images");+ assert.deepEqual(r.calls, ["/hub", "/library", "/images"]);+});++test("Back off an unrendered sidebar entry, then Forward onto it, keeps it", () => {+ const r = fakeRouter();+ r.click("/hub");+ r.back();+ r.render();+ r.forward();+ r.click("/images");+ assert.deepEqual(r.hrefs(), ["/chat", "/hub", "/images"]);+});++test("clicks held by a blocker never replace the entry on screen", () => {+ const r = fakeRouter("/library", { blocked: true });+ r.click("/hub");+ r.click("/images");+ assert.deepEqual(r.calls, ["/hub", "/images"]);+});++test("sidebar rows and chat rows navigate through the coalescer", async () => {+ const source = await readSrcAsync("components/app-sidebar.tsx");+ for (const to of ["/library", "/hub", "/images", "/studio", "/projects"]) {+ assert.match(+ source,+ new RegExp(`navigateFromRow\\(\\{ to: "${to}" \\}\\)`),+ );+ }+ assert.match(+ source,+ /function openChatItem\(item: SidebarItem\) \{[\s\S]*?navigateFromRow\(\{\s*to: "\/chat",/,+ );+ assert.match(+ source,+ /currentEntry: \(\) => router\.latestLocation\.state\.__TSR_key/,+ );+ assert.match(source, /router\.subscribe\("onResolved"/);+});