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: keep the sidebar's bottom fade in step with the list (#12423)
Michael Hanf864051afaff
diff --git a/studio/frontend/src/components/app-sidebar.tsx b/studio/frontend/src/components/app-sidebar.tsxindex 38851a01245..76af913c944 100644--- a/studio/frontend/src/components/app-sidebar.tsx+++ b/studio/frontend/src/components/app-sidebar.tsx@@ -1072,7 +1072,25 @@ export function AppSidebar() {const scrollRef = useRef<HTMLDivElement | null>(null);const [scrolled, setScrolled] = useState(false);// Bottom fade hides at the very bottom / for short lists so the last row isn't washed out.- const [canScrollDown, setCanScrollDown] = useState(false);+ // Written to the DOM like the rail: the observer below drives it, and state there loops (#185).+ const fadeRef = useRef<HTMLDivElement | null>(null);+ const syncFade = useCallback((el: HTMLDivElement) => {+ const fade = fadeRef.current;+ if (!fade) return;+ // Only rows count: what is left below the bottom padding. Scrolling also grows the pinned+ // group above by a few px, which leaves that much padding out of view at the very bottom.+ const hidden = el.scrollHeight - el.scrollTop - el.clientHeight;+ const visible = String(hidden > parseFloat(getComputedStyle(el).paddingBottom) + 1);+ if (fade.dataset.visible !== visible) fade.dataset.visible = visible;+ }, []);+ // The footer mounts after the scroller, so the first measure lands here.+ const attachFade = useCallback(+ (node: HTMLDivElement | null) => {+ fadeRef.current = node;+ if (node && scrollRef.current) syncFade(scrollRef.current);+ },+ [syncFade],+ );// Rail width: 0 where scrollbars overlay (macOS default) or the list fits, the platform's thin rail// where they are classic. Only rows inside the scroller lose it, so the rows outside pad by it to// keep one edge. Written to the DOM, and only on a change: state here would loop (React #185).@@ -1088,38 +1106,59 @@ export function AppSidebar() {// swaps it for the desktop one, so the scroller is a new node each time and an effect keyed on a// stable callback never re-runs. Still runs before paint.const railObserverRef = useRef<ResizeObserver | null>(null);+ const sectionObserverRef = useRef<MutationObserver | null>(null);const attachScroller = useCallback((el: HTMLDivElement | null) => {railObserverRef.current?.disconnect();railObserverRef.current = null;+ sectionObserverRef.current?.disconnect();+ sectionObserverRef.current = null;scrollRef.current = el;// Per node: a new parent has no variable yet even at the same rail, and// the cache would otherwise skip the write.railWidthRef.current = null;if (!el) return;measureScrollRail(el);+ syncFade(el);// Watch the box, not renders: the Images disclosure and the project toggles change the row count// without rendering this component, and a scrollbar appearing shrinks the content box. Safe where- // the earlier observer was not: it writes a variable, never state, so nothing feeds back.- const observer = new ResizeObserver(() => measureScrollRail(el));+ // the earlier observer was not: it writes the DOM, never state, so nothing feeds back.+ const observer = new ResizeObserver(() => {+ measureScrollRail(el);+ syncFade(el);+ });observer.observe(el);+ // The sections too, so the fade follows the content height, not just the box.+ for (const section of el.children) observer.observe(section);+ // Sections come and go with their disclosures. A new one reports its size on its own; a gone+ // one is unobserved, or the observer keeps the detached subtree alive, so re-measure here.+ const sections = new MutationObserver((records) => {+ for (const record of records) {+ for (const node of record.removedNodes) {+ if (node instanceof Element) observer.unobserve(node);+ }+ for (const node of record.addedNodes) {+ if (node instanceof Element) observer.observe(node);+ }+ }+ syncFade(el);+ });+ sections.observe(el, { childList: true });railObserverRef.current = observer;+ sectionObserverRef.current = sections;},- [measureScrollRail],+ [measureScrollRail, syncFade],);- // Driven only from onScroll + a content-change effect below. No- // ResizeObserver: its callback-driven setState caused a render loop (React- // #185). Both setters bail out when unchanged, so neither path can loop.- const syncScrollState = useCallback((el: HTMLDivElement) => {- const nextScrolled = el.scrollTop > 0;- setScrolled((prev) => (prev === nextScrolled ? prev : nextScrolled));- const nextCanScrollDown =- el.scrollHeight - el.scrollTop - el.clientHeight > 1;- setCanScrollDown((prev) =>- prev === nextCanScrollDown ? prev : nextCanScrollDown,- );- }, []);+ // The setter bails out when unchanged, so this cannot loop.+ const syncScrollState = useCallback(+ (el: HTMLDivElement) => {+ const nextScrolled = el.scrollTop > 0;+ setScrolled((prev) => (prev === nextScrolled ? prev : nextScrolled));+ syncFade(el);+ },+ [syncFade],+ );const isRecipesRoute = pathname.startsWith("/data-recipes");const isExportRoute = pathname === "/export" || pathname.startsWith("/export/");@@ -1688,20 +1727,7 @@ export function AppSidebar() {return next;});}, []);- // Rows the open custom sections draw. Creating, filling, hiding or folding one changes the list's- // height with no scroll to re-measure the bottom fade off.- const customSectionRowCount = useMemo(- () =>- visibleCustomSections.reduce(- (count, section) =>- collapsedSectionIds.has(section.id)- ? count- : count + (customSectionRows.get(section.id)?.length ?? 0),- 0,- ),- [visibleCustomSections, collapsedSectionIds, customSectionRows],- );- // The folders the custom sections draw, open or not: the bottom fade counts their chats.+ // The folders the custom sections draw, open or not.const customSectionProjectRecords = useMemo(() =>visibleCustomSections.flatMap((section) =>@@ -1909,35 +1935,6 @@ export function AppSidebar() {}return map;}, [sortedChatsByProjectId]);- // Nested rows across both sections, so the bottom fade re-measures when the list height changes.- const projectChatRowCount = useMemo(() => {- // Only folders list chats, and only this organization has folders that do.- if (organizeBy !== "project") return 0;- let rows = 0;- for (const project of [- ...pinnedProjectRecords,- ...customSectionProjectRecords,- ...visibleProjectRecords,- ]) {- if (collapsedProjectIds.has(project.id)) continue;- const chats = sortedChatsByProjectId.get(project.id) ?? [];- rows += expandedChatProjectIds.has(project.id)- ? chats.length- : Math.min(chats.length, PROJECT_CHAT_LIMIT);- // "Show more" and an empty folder's "No chats" are rows too.- if (chats.length > PROJECT_CHAT_LIMIT) rows += 1;- if (chats.length === 0) rows += 1;- }- return rows;- }, [- organizeBy,- pinnedProjectRecords,- customSectionProjectRecords,- visibleProjectRecords,- collapsedProjectIds,- expandedChatProjectIds,- sortedChatsByProjectId,- ]);// Multi-select. Ids only: a row that gets deleted elsewhere drops out of// selectedChatItems on its own rather than leaving a ghost to act on.@@ -2522,54 +2519,6 @@ export function AppSidebar() {// The Train-page status poll doesn't run off-route; keep state fresh so the spinner clears.useTrainingCompletionWatch();- // Recompute bottom-fade on mount and whenever list height can change: onScroll never fires- // for short, non-scrolling lists. Guarded setState below can't loop.- useEffect(() => {- const el = scrollRef.current;- if (!el) return;- const next = el.scrollHeight - el.scrollTop - el.clientHeight > 1;- setCanScrollDown((prev) => (prev === next ? prev : next));- }, [- recentChatItems.length,- runItems.length,- projects.length,- chatOpen,- runsOpen,- pinnedOpen,- isStudioRoute,- // The update card grows the footer, so the scroll area shrinks under it.- showUpdateCard,- // Regrouping, collapsing a folder or revealing more adds and removes rows- // with no scroll and no collapsible animation to re-measure off.- projectsOpen,- projectChatRowCount,- visibleProjectRecords.length,- // Pinning a folder moves rows between sections, leaving both counts above unchanged.- pinnedProjectRecords.length,- // Pinning a project chat adds a Pinned row while Recents and the folder- // counts both stay put, so nothing else here moves.- pinnedChatItems.length,- // And with no chats in them, folders appear and disappear on their own.- organizeBy,- // Custom sections: an empty one still draws its header and hint, and folding it hides both.- visibleCustomSections.length,- collapsedSectionIds,- customSectionRowCount,- projectsSectionHidden,- ]);-- // Resizing changes clientHeight without firing onScroll, so the fade would- // stay hidden while rows are still clipped. Window events only: no element- // observer, so this can't feed back into the loop that caused React #185.- useEffect(() => {- const onResize = () => {- const el = scrollRef.current;- if (el) syncScrollState(el);- };- window.addEventListener("resize", onResize);- return () => window.removeEventListener("resize", onResize);- }, [syncScrollState]);-const chatDisabled = trainingInProgress;const usesDesktopTitlebar = usesCustomTitlebar || usesNativeMacTitlebar;@@ -3865,8 +3814,7 @@ export function AppSidebar() {block to the bottom of the section, so every pixel down there is inside itand a chat meant to go after the folder was filed into it instead.Always drawn, never only while a row is carried: a row appearing at drag- start shifts every section under it after the pointer was sampled, and the- bottom fade measures a height this one would not be counted in.+ start shifts every section under it after the pointer was sampled.It draws its own line, since the line under the folder's last chat alreadymeans "into the folder, last" and the same pixels cannot mean both. */}<SidebarMenuItem@@ -5649,6 +5597,7 @@ export function AppSidebar() {shows fully (Gemini-style). Stops at the rail: the thumb ends itstravel in this band and a full-width gradient washed it out. */}<div+ ref={attachFade}aria-hidden="true"className={cn(// The scroll area hard-clips at the fade's bottom edge, so a plain ramp is still part-transparent@@ -5658,7 +5607,8 @@ export function AppSidebar() {// Shorter fade with the update card so the list reads closer to// it, but still tall enough to clear a row.showUpdateCard ? "h-7" : "h-10",- canScrollDown ? "opacity-100" : "opacity-0",+ // data-visible is written by syncFade, not React.+ "opacity-0 data-[visible=true]:opacity-100",)}/>{/* Collapsed: cog sits one nav-row step above the avatar. */}diff --git a/studio/frontend/tests/sidebar-action-rows-inert.test.ts b/studio/frontend/tests/sidebar-action-rows-inert.test.tsindex 229793a6a3c..d52fc623c0f 100644--- a/studio/frontend/tests/sidebar-action-rows-inert.test.ts+++ b/studio/frontend/tests/sidebar-action-rows-inert.test.ts@@ -123,10 +123,15 @@ test("the sidebar list measures its scroll rail", async () => {// appearing shrinks the content box.assert.match(source,- /const observer = new ResizeObserver\(\(\) => measureScrollRail\(el\)\);\s*observer\.observe\(el\);\s*railObserverRef\.current = observer;/,+ /const observer = new ResizeObserver\(\(\) => \{\s*measureScrollRail\(el\);\s*syncFade\(el\);\s*\}\);\s*observer\.observe\(el\);/,);- // Writes a variable, never state: that pairing is what looped.+ // Writes the DOM, never state: that pairing is what looped.assert.equal(/new ResizeObserver\([^)]*set[A-Z]/.test(source), false);+ assert.match(source, /if \(fade\.dataset\.visible !== visible\) fade\.dataset\.visible = visible;/);+ assert.equal(/setCanScrollDown/.test(source), false);+ // The sections too, so the fade follows content that grows without rendering AppSidebar.+ assert.match(source, /for \(const section of el\.children\) observer\.observe\(section\);/);+ assert.match(source, /sections\.observe\(el, \{ childList: true \}\);/);// And only on a change, so it cannot re-trigger itself.assert.match(source, /if \(rail === railWidthRef\.current\) return;/);// The fade stops at the rail too: the thumb ends its travel in that band.diff --git a/studio/frontend/tests/sidebar-custom-sections.test.ts b/studio/frontend/tests/sidebar-custom-sections.test.tsindex 9fbe5564c95..c940f115f94 100644--- a/studio/frontend/tests/sidebar-custom-sections.test.ts+++ b/studio/frontend/tests/sidebar-custom-sections.test.ts@@ -941,13 +941,8 @@ test("a chat filed from its menu while its drop into a folder is in flight keeps});test("custom sections re-measure the bottom fade when they change the list's height", () => {- const deps = APP_SIDEBAR.slice(- APP_SIDEBAR.indexOf("// Recompute bottom-fade on mount"),- APP_SIDEBAR.indexOf("// Resizing changes clientHeight"),- );- for (const dep of ["visibleCustomSections.length", "collapsedSectionIds", "customSectionRowCount", "projectsSectionHidden"]) {- assert.ok(deps.includes(` ${dep},\n`), dep);- }+ // They draw inside the scroller, whose sections the fade observer watches.+ assert.match(APP_SIDEBAR, /for \(const section of el\.children\) observer\.observe\(section\);/);});test("Alt + arrow on a section's header moves it, as it moves a row", async () => {diff --git a/studio/frontend/tests/sidebar-row-menu-and-pinned-folders.test.ts b/studio/frontend/tests/sidebar-row-menu-and-pinned-folders.test.tsindex a20a1d368e5..096c5ca5df6 100644--- a/studio/frontend/tests/sidebar-row-menu-and-pinned-folders.test.ts+++ b/studio/frontend/tests/sidebar-row-menu-and-pinned-folders.test.ts@@ -95,8 +95,6 @@ test("an empty open folder says it is empty", () => {APP_SIDEBAR,/\{expanded && projectChats\.length === 0 && \(\n\s*<SidebarMenuItem\n\s*\{\.\.\.dnd\.dropZoneProps\(\{ section: order\.section, folderId: project\.id, blockEnd \}\)\}\n\s*>\n\s*<p className="[^"]*text-nav-fg-muted">\n\s*\{t\("shell\.navigation\.noChats"\)\}/,);- // And it is a row, so the bottom fade has to count it like the "Show more" one.- assert.match(APP_SIDEBAR, /if \(chats\.length === 0\) rows \+= 1;/);});// A chat's "Move to" holds projects and sections, each its own group under a heading: its New@@ -415,11 +413,6 @@ test("a pinned folder in one list is a way in, not a second copy of its chats",]) {assert.match(APP_SIDEBAR, gated);}- // And the row count the scroll fade measures counts nothing where nothing is drawn.- assert.match(- APP_SIDEBAR,- /const projectChatRowCount = useMemo\(\(\) => \{\n[^\n]*\n\s*if \(organizeBy !== "project"\) return 0;/,- );});// "Remove from <name>", and lists that scroll: forty projects ran the submenu off the window,diff --git a/studio/frontend/tests/sidebar-scroll-fade-deps.test.ts b/studio/frontend/tests/sidebar-scroll-fade-deps.test.tsindex 79331d09298..5de97c26751 100644--- a/studio/frontend/tests/sidebar-scroll-fade-deps.test.ts+++ b/studio/frontend/tests/sidebar-scroll-fade-deps.test.ts@@ -6,38 +6,28 @@ import test from "node:test";import { readSrcAsync } from "./helpers/kit.ts";-// onScroll never fires for a list that is not scrolling, so the bottom fade is-// only re-measured when this effect re-runs. Every input that can add or remove-// a row has to be in its deps, and a missing one is invisible: the fade just-// stays wrong until an unrelated scroll or resize.+// onScroll never fires for a list that is not scrolling, and rows can change without rendering+// AppSidebar (the Images disclosure, project toggles, data landing at startup). The bottom fade+// follows the scroller's size instead of a list of row inputs, which went stale on any it missed.-test("the bottom fade re-measures on every row-count input", async () => {+test("the bottom fade re-measures off the list's size, not its row inputs", async () => {const source = await readSrcAsync("components/app-sidebar.tsx");- const effect =- /Recompute bottom-fade on mount[\s\S]*?\}, \[([\s\S]*?)\n \]\);/.exec(- source,- );- assert.ok(effect, "could not find the bottom-fade effect");- const deps = effect[1];-- for (const dep of [- // Each list that renders rows into the scroller.- "recentChatItems.length",- "pinnedChatItems.length",- "projectChatRowCount",- "visibleProjectRecords.length",- "runItems.length",- // Disclosures, which hide and reveal whole sections.- "chatOpen",- "runsOpen",- "pinnedOpen",- "projectsOpen",- // Regrouping, which can empty or fill the Projects section outright.- "organizeBy",- ]) {- assert.ok(- deps.includes(dep),- `${dep} is missing from the bottom-fade deps, so the fade goes stale when it changes`,- );- }+ assert.equal(/Recompute bottom-fade on mount/.test(source), false);+ assert.equal(/window\.addEventListener\("resize"/.test(source), false);+ // The box and every section in it, including ones that mount later.+ assert.match(source, /observer\.observe\(el\);/);+ assert.match(source, /for \(const section of el\.children\) observer\.observe\(section\);/);+ assert.match(source, /sections\.observe\(el, \{ childList: true \}\);/);+ // A section that leaves is unobserved, so the observer does not hold its detached subtree,+ // and the fade re-measures since an unobserved node reports nothing.+ assert.match(source, /if \(node instanceof Element\) observer\.unobserve\(node\);/);+ assert.match(source, /if \(node instanceof Element\) observer\.observe\(node\);/);+ assert.match(source, /observer\.observe\(node\);\s*\}\s*\}\s*syncFade\(el\);/);+ // Measured on attach from both ends, since the footer mounts after the scroller.+ assert.match(source, /measureScrollRail\(el\);\s*syncFade\(el\);/);+ assert.match(source, /if \(node && scrollRef\.current\) syncFade\(scrollRef\.current\);/);+ // React never owns the attribute, so a render cannot reset it.+ assert.match(source, /ref=\{attachFade\}/);+ assert.match(source, /"opacity-0 data-\[visible=true\]:opacity-100"/);+ assert.equal(/data-visible=/.test(source), false);});