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
Read the sidebar pin's width only where matchMedia exists, and expect the update card's scaled width (#11700)
Daniel Hand79753c3ba63
diff --git a/studio/frontend/src/hooks/use-sidebar-pin.ts b/studio/frontend/src/hooks/use-sidebar-pin.tsindex c315230126a..e1fd3c1d6dd 100644--- a/studio/frontend/src/hooks/use-sidebar-pin.ts+++ b/studio/frontend/src/hooks/use-sidebar-pin.ts@@ -15,10 +15,17 @@ function readStored(): boolean | null {}}+// Null where there is no matchMedia to ask (a test's partial window, or a host that lacks it).+// This module reads it at import time, so a throw here fails every importer, not one call.+function wideQuery(): MediaQueryList | null {+ return typeof window.matchMedia === "function" ? window.matchMedia(WIDE_QUERY) : null;+}+function loadPinned(): boolean {if (typeof window === "undefined") return true;- // Default to unpinned below lg, also when storage is unavailable.- return readStored() ?? window.matchMedia(WIDE_QUERY).matches;+ // Default to unpinned below lg, also when storage is unavailable. With no width to read,+ // keep the desktop default, as when there is no window at all.+ return readStored() ?? wideQuery()?.matches ?? true;}let pinnedValue = loadPinned();@@ -45,18 +52,18 @@ function subscribe(cb: () => void) {}};// Re-derive the width default across lg unless the user has chosen.- const wide = window.matchMedia(WIDE_QUERY);+ const wide = wideQuery();const onWidth = () => {if (chosen || held) return;pinnedValue = loadPinned();cb();};window.addEventListener("storage", onStorage);- wide.addEventListener("change", onWidth);+ wide?.addEventListener("change", onWidth);return () => {listeners.delete(cb);window.removeEventListener("storage", onStorage);- wide.removeEventListener("change", onWidth);+ wide?.removeEventListener("change", onWidth);};}diff --git a/studio/frontend/tests/sidebar-pin-without-matchmedia.test.ts b/studio/frontend/tests/sidebar-pin-without-matchmedia.test.tsnew file mode 100644index 00000000000..835756174e9--- /dev/null+++ b/studio/frontend/tests/sidebar-pin-without-matchmedia.test.ts@@ -0,0 +1,59 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++// use-sidebar-pin reads the lg media query when it is imported. #11660 made that read+// unconditional, and every test whose import graph reaches the window titlebar supplies a+// partial `window` with no matchMedia, so the import threw and took the whole file down+// (training-dataset-source-transitions.test.ts, on main).++import assert from "node:assert/strict";+import test from "node:test";++const storage = {+ getItem: () => null,+ setItem: () => undefined,+ removeItem: () => undefined,+};++function stubWindow(matchMedia?: (query: string) => unknown) {+ const listeners: string[] = [];+ const target: Record<string, unknown> = {+ addEventListener: (type: string) => listeners.push(type),+ removeEventListener: () => undefined,+ localStorage: storage,+ };+ if (matchMedia) target.matchMedia = matchMedia;+ Object.assign(globalThis, { window: target });+ return listeners;+}++let loads = 0;+async function load() {+ loads += 1;+ return import(`../src/hooks/use-sidebar-pin.ts?load=${loads}`);+}++test("the pin module imports, holds and releases where there is no matchMedia", async () => {+ stubWindow();+ const pin = await load();+ pin.holdSidebarPinned();+ // Release re-derives the width default, the second place the query is read.+ pin.releaseSidebarPinned();+});++test("with matchMedia the width default still comes from the lg query", async () => {+ const queries: string[] = [];+ stubWindow((query) => {+ queries.push(query);+ return {+ matches: false,+ addEventListener: () => undefined,+ removeEventListener: () => undefined,+ };+ });+ const pin = await load();+ assert.deepEqual(queries, ["(min-width: 1024px)"]);+ pin.holdSidebarPinned();+ pin.releaseSidebarPinned();+ assert.deepEqual(queries, ["(min-width: 1024px)", "(min-width: 1024px)"]);+});diff --git a/tests/studio/playwright_update_banner_layout.py b/tests/studio/playwright_update_banner_layout.pyindex 7e916579b0f..db3e823061f 100644--- a/tests/studio/playwright_update_banner_layout.py+++ b/tests/studio/playwright_update_banner_layout.py@@ -365,6 +365,8 @@ UI_FONT_SIZE_MAX = 20UI_FONT_SIZE_DEFAULT = 15UI_FONT_SIZE_CSS_BASE = 16# --ui-font-scale as a number, read through a length since the property itself is a calc().+# --ui-space-scale the same way: the card's max width is calc(448px * var(--ui-space-scale, 1)) since #11648.+UI_SPACE_SCALE_JS = "(() => { const probe = document.createElement('div'); probe.style.cssText = 'position:absolute;visibility:hidden;width:calc(10000px * var(--ui-space-scale, 1))'; document.body.appendChild(probe); const px = parseFloat(getComputedStyle(probe).width); probe.remove(); return String(px / 10000); })()"UI_FONT_SCALE_JS = "(() => { const probe = document.createElement('div'); probe.style.cssText = 'position:absolute;visibility:hidden;width:calc(10000px * var(--ui-font-scale, 1))'; document.body.appendChild(probe); const px = parseFloat(getComputedStyle(probe).width); probe.remove(); return String(px / 10000); })()"APPEARANCE_STORE_VERSION = 5@@ -686,8 +688,10 @@ def measure(page, label: str) -> dict:f"{name}={seen}",)if facts["cardLayoutWidth"] is not None:- # 448px is the card's max width and 2rem the viewport inset it keeps.- want = min(448, view["width"] - 32)+ # 448px at the default size is the card's max width, scaled with the UI since #11648, and 2rem the+ # viewport inset it keeps.+ space = float(page.evaluate("() => " + UI_SPACE_SCALE_JS))+ want = min(448 * space, view["width"] - 32)# Asked of the layout box, not the painted one. A scrollbar that takes its width out of the rail's content box# shrinks the card's layout width, which is the whole subject here; the card's enter animation (opacity 0,# y 12, scale .96 -- see components/*/update-banner.tsx) shrinks only the painted one, and measuring that@@ -697,7 +701,7 @@ def measure(page, label: str) -> dict:check(f"{label}: the card keeps its full width whatever the scrollbar does",abs(facts["cardLayoutWidth"] - want) <= 1,- f"cardLayoutWidth={facts['cardLayoutWidth']} want={want} "+ f"cardLayoutWidth={facts['cardLayoutWidth']} want={want} spaceScale={space} "f"cardPaintedWidth={facts['cardWidth']} "f"railGutter={facts['railGutterPx']} scrolls={facts['railScrolls']} "f"why={json.dumps(facts['widthWhy'], sort_keys = True)}",