From 85314ed1622cbdcbd6621ebf97307606f4baf89d Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Mon, 8 Jun 2026 23:10:35 -0700 Subject: [PATCH] Studio frontend: reduce and tighten code comments (#6099) Trim and tighten code comments across studio/frontend TS/JS. Comment-only: every changed file verified code-identical to main via the TypeScript printer signature comparison. --- studio/frontend/src/app/provider.tsx | 18 +- studio/frontend/src/app/routes/__root.tsx | 4 +- studio/frontend/src/app/routes/settings.tsx | 8 +- .../frontend/src/components/app-sidebar.tsx | 51 ++- .../components/assistant-ui/attachment.tsx | 4 +- .../components/assistant-ui/code-plugin.ts | 4 +- .../components/assistant-ui/code-themes.ts | 9 +- .../src/components/assistant-ui/image.tsx | 5 +- .../components/assistant-ui/markdown-text.tsx | 18 +- .../assistant-ui/message-timing.tsx | 7 +- .../model-selector/folder-browser.tsx | 41 +-- .../assistant-ui/model-selector/pickers.tsx | 78 ++--- .../src/components/assistant-ui/reasoning.tsx | 6 +- .../src/components/assistant-ui/sources.tsx | 24 +- .../assistant-ui/think-aria-label.ts | 7 +- .../src/components/assistant-ui/thread.tsx | 216 ++++++------ .../assistant-ui/tool-call-spinner.tsx | 6 +- .../components/assistant-ui/tool-group.tsx | 4 +- .../assistant-ui/tool-ui-code-execution.tsx | 14 +- .../assistant-ui/tool-ui-image-generation.tsx | 28 +- .../assistant-ui/tool-ui-python.tsx | 2 +- .../assistant-ui/tool-ui-render-html.tsx | 9 +- .../assistant-ui/tool-ui-web-search.tsx | 5 +- .../use-intent-aware-autoscroll.tsx | 276 ++++++--------- .../src/components/shutdown-dialog.tsx | 9 +- .../src/components/tauri/window-titlebar.tsx | 2 +- studio/frontend/src/config/env.ts | 10 +- studio/frontend/src/features/auth/api.ts | 12 +- .../features/auth/components/auth-form.tsx | 28 +- studio/frontend/src/features/auth/session.ts | 13 +- .../src/features/auth/tauri-auto-auth.ts | 6 +- .../src/features/chat/api-provider-logo.tsx | 9 +- .../src/features/chat/api/chat-adapter.ts | 327 ++++++++---------- .../src/features/chat/api/chat-api.ts | 46 ++- .../features/chat/api/openai-containers.ts | 14 +- .../src/features/chat/api/providers-api.ts | 7 +- .../chat/artifacts/artifact-surface.tsx | 7 +- .../features/chat/artifacts/html-frame.tsx | 5 +- .../src/features/chat/artifacts/types.ts | 4 +- .../features/chat/chat-mcp-servers-dialog.tsx | 7 +- .../frontend/src/features/chat/chat-page.tsx | 168 ++++----- .../features/chat/chat-providers-dialog.tsx | 12 +- .../src/features/chat/chat-settings-sheet.tsx | 44 +-- .../chat/components/context-usage-bar.tsx | 2 +- .../chat/components/model-load-status.tsx | 21 +- .../components/openai-code-exec-section.tsx | 209 +++++------ studio/frontend/src/features/chat/db.ts | 5 +- .../src/features/chat/external-providers.ts | 63 ++-- .../chat/hooks/use-chat-model-runtime.ts | 65 ++-- .../chat/hooks/use-chat-search-index.ts | 7 +- .../chat/hooks/use-chat-sidebar-items.ts | 5 +- .../chat/hooks/use-pill-activation-order.ts | 5 +- .../features/chat/hooks/use-transfer-stats.ts | 20 +- .../src/features/chat/lib/friendly-names.ts | 37 +- .../src/features/chat/mcp-composer-button.tsx | 15 +- .../features/chat/provider-capabilities.ts | 224 +++++------- .../src/features/chat/runtime-provider.tsx | 45 ++- .../src/features/chat/shared-composer.tsx | 154 ++++----- .../chat/stores/chat-runtime-store.ts | 132 ++++--- .../frontend/src/features/chat/tour/steps.tsx | 4 +- studio/frontend/src/features/chat/types.ts | 31 +- .../frontend/src/features/chat/types/api.ts | 75 ++-- .../src/features/chat/types/runtime.ts | 4 +- .../chat/utils/chat-history-storage.ts | 62 ++-- .../chat/utils/chat-thread-tombstones.ts | 10 +- .../chat/utils/delete-thread-message.ts | 17 +- .../features/chat/utils/format-transfer.ts | 20 +- .../chat/utils/image-input-support.ts | 13 +- .../chat/utils/parse-assistant-content.ts | 8 +- .../src/features/chat/utils/transfer-stats.ts | 35 +- .../src/features/export/api/export-api.ts | 6 +- .../export/components/export-dialog.tsx | 84 ++--- .../src/features/export/export-page.tsx | 13 +- .../components/steps/hyperparameters-step.tsx | 8 +- .../components/steps/model-selection-step.tsx | 2 +- .../components/steps/model-type-step.tsx | 2 +- .../src/features/profile/utils/jwt-subject.ts | 4 +- .../profile/utils/resize-image-file.ts | 4 +- .../components/executions/executions-view.tsx | 8 +- .../components/inline/inline-model.tsx | 6 +- .../models/local-recipe-model-selector.tsx | 4 +- .../dialogs/models/model-config-dialog.tsx | 6 +- .../hooks/use-recipe-executions.ts | 21 +- .../recipe-studio/recipe-studio-page.tsx | 44 ++- .../recipe-studio/stores/recipe-studio.ts | 7 +- .../recipe-studio/utils/graph/fit-view.ts | 15 +- .../utils/graph/recipe-graph-connection.ts | 8 +- .../features/recipe-studio/utils/layout.ts | 24 +- .../utils/payload/builders-model.ts | 9 +- .../utils/payload/builders-sampler.ts | 2 +- .../settings/components/create-key-form.tsx | 5 +- .../src/features/settings/settings-dialog.tsx | 15 +- .../settings/stores/settings-dialog-store.ts | 8 +- .../features/settings/stores/theme-store.ts | 16 +- .../features/settings/tabs/api-keys-tab.tsx | 5 +- .../features/settings/tabs/general-tab.tsx | 19 +- .../studio/historical-training-view.tsx | 4 +- .../src/features/studio/history-card-grid.tsx | 14 +- .../dataset-preview-dialog-mapping.tsx | 4 +- .../sections/dataset-preview-dialog.tsx | 14 +- .../studio/sections/model-section.tsx | 8 +- .../studio/sections/progress-section.tsx | 2 +- .../studio/sections/training-section.tsx | 11 +- .../src/features/studio/studio-page.tsx | 6 +- .../studio/training-start-overlay.tsx | 28 +- .../features/tour/lib/confetti-fireworks.ts | 7 +- .../src/features/training/api/models-api.ts | 10 +- .../training/hooks/use-training-actions.ts | 4 +- .../hooks/use-training-history-sidebar.ts | 12 +- .../hooks/use-training-unload-guard.ts | 7 +- .../src/features/training/lib/yaml-config.ts | 8 +- .../training/stores/training-config-store.ts | 44 +-- .../src/hooks/use-collapse-scroll-lock.ts | 10 +- studio/frontend/src/hooks/use-gpu-info.ts | 6 +- .../frontend/src/hooks/use-gpu-utilization.ts | 6 +- .../frontend/src/hooks/use-hardware-info.ts | 8 +- .../src/hooks/use-hf-dataset-search.ts | 4 +- .../src/hooks/use-hf-dataset-splits.ts | 5 +- .../frontend/src/hooks/use-hf-model-search.ts | 51 ++- .../src/hooks/use-hf-token-validation.ts | 5 +- .../src/hooks/use-recommended-model-vram.ts | 4 +- .../frontend/src/hooks/use-tauri-backend.ts | 29 +- studio/frontend/src/lib/copy-to-clipboard.ts | 8 +- .../frontend/src/lib/format-fastapi-error.ts | 15 +- studio/frontend/src/lib/hf-cache.ts | 11 +- studio/frontend/src/lib/latex.ts | 65 ++-- studio/frontend/src/lib/open-link.ts | 11 +- studio/frontend/src/lib/vram.ts | 61 +--- studio/frontend/src/main.tsx | 4 +- studio/frontend/src/utils/index.ts | 1 - 130 files changed, 1553 insertions(+), 2141 deletions(-) diff --git a/studio/frontend/src/app/provider.tsx b/studio/frontend/src/app/provider.tsx index 6f3c7618be..4bd348effc 100644 --- a/studio/frontend/src/app/provider.tsx +++ b/studio/frontend/src/app/provider.tsx @@ -48,11 +48,10 @@ async function applyAppWindowLayout(isCurrent: WindowLayoutGuard): Promise const win = getCurrentWindow(); // Decide first-launch vs restore from the on-disk state file BEFORE touching the - // window. Probing the window itself after restoreStateCurrent is unreliable: - // on GTK, set_size against a hidden window is deferred until show(), so - // innerSize() reads a stale value and any baseline fallback would overwrite the - // queued restore. On macOS the same probe works, hence the inconsistency - // between previous iterations of this code. + // window. Probing the window after restoreStateCurrent is unreliable: on GTK, + // set_size on a hidden window is deferred until show(), so innerSize() reads a + // stale value and a baseline fallback would overwrite the queued restore. On + // macOS the same probe works, hence the inconsistency between prior iterations. const hasSavedState = await invoke("has_saved_window_state"); if (!isCurrent()) return; @@ -60,9 +59,8 @@ async function applyAppWindowLayout(isCurrent: WindowLayoutGuard): Promise if (!isCurrent()) return; if (hasSavedState) { - // Subsequent launch: the plugin handles size, position, and maximized, - // with built-in off-screen protection (monitor-intersection check) for - // positions saved on a now-disconnected display. + // Subsequent launch: plugin restores size/position/maximized, with built-in + // off-screen protection for positions saved on a now-disconnected display. await restoreStateCurrent( StateFlags.SIZE | StateFlags.POSITION | StateFlags.MAXIMIZED, ); @@ -87,8 +85,8 @@ async function applyAppWindowLayout(isCurrent: WindowLayoutGuard): Promise if (!isCurrent()) return; await win.show(); if (!isCurrent()) return; - // Apply constraints after restore/show. Setting constraints before plugin restore - // can emit a Resized event and overwrite the plugin's cached saved size. + // Apply constraints after restore/show: doing so before plugin restore can emit + // a Resized event and overwrite the plugin's cached saved size. await win.setSizeConstraints({ minWidth: MIN_WINDOW_WIDTH, minHeight: MIN_WINDOW_HEIGHT }); } diff --git a/studio/frontend/src/app/routes/__root.tsx b/studio/frontend/src/app/routes/__root.tsx index da74a9e8a7..200200d190 100644 --- a/studio/frontend/src/app/routes/__root.tsx +++ b/studio/frontend/src/app/routes/__root.tsx @@ -55,8 +55,8 @@ function isChatOnlyAllowed(pathname: string): boolean { export const Route = createRootRoute({ beforeLoad: async ({ location }) => { - // Ensure platform info is fetched before checking chat-only guard. - // fetchDeviceType caches after first call, so subsequent navigations are instant. + // Fetch platform info before the chat-only guard. fetchDeviceType caches, + // so later navigations are instant. await fetchDeviceType(); const chatOnly = usePlatformStore.getState().isChatOnly(); if (chatOnly && !isChatOnlyAllowed(location.pathname)) { diff --git a/studio/frontend/src/app/routes/settings.tsx b/studio/frontend/src/app/routes/settings.tsx index fa97a450f7..84650bdb8b 100644 --- a/studio/frontend/src/app/routes/settings.tsx +++ b/studio/frontend/src/app/routes/settings.tsx @@ -7,10 +7,10 @@ import { useSettingsDialogStore } from "@/features/settings"; import { requireAuth } from "../auth-guards"; import { Route as rootRoute } from "./__root"; -// /settings is a deep link to the modal. Open it, then redirect home. -// Tab title is driven by useSettingsDialogStore in __root.tsx since the -// redirect means /settings never stays matched; staticData is just a -// safety net if beforeLoad ever stops throwing. +// /settings deep-links the modal: open it, then redirect home. Tab title is +// driven by useSettingsDialogStore in __root.tsx since the redirect means +// /settings never stays matched; staticData is a safety net if beforeLoad +// ever stops throwing. export const Route = createRoute({ getParentRoute: () => rootRoute, path: "/settings", diff --git a/studio/frontend/src/components/app-sidebar.tsx b/studio/frontend/src/components/app-sidebar.tsx index 941c2e8a74..8d56d90f98 100644 --- a/studio/frontend/src/components/app-sidebar.tsx +++ b/studio/frontend/src/components/app-sidebar.tsx @@ -138,11 +138,8 @@ function getTourId(pathname: string): string | null { return null; } -// Hugeicons' TestTube01Icon ships with two interior bubbles (paths #4 -// and #5 of the 5-path definition). Slicing to the first three paths -// keeps the test-tube outline + horizontal cap + liquid line, dropping -// the bubbles. The original export stays untouched, and HugeiconsIcon -// renders this trimmed array exactly the same way. +// TestTube01Icon's last 2 paths are interior bubbles; slice to the first +// 3 (outline + cap + liquid line) to drop them. Original export untouched. const TestTubeOutlineIcon = TestTube01Icon.slice( 0, 3, @@ -261,11 +258,11 @@ export function AppSidebar() { const scrollRef = useRef(null); const [scrolled, setScrolled] = useState(false); - // Bottom fade hides at the very bottom (and for short, non-scrolling lists) - // so the last row isn't washed out - Gemini-style. + // Bottom fade hides at the very bottom / for short lists so the last row + // isn't washed out (Gemini-style). const [canScrollDown, setCanScrollDown] = useState(false); - // Driven only from onScroll + a content-change effect below. Deliberately NO - // ResizeObserver: its callback-driven setState created a render loop (React + // 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 = (el: HTMLDivElement) => { const nextScrolled = el.scrollTop > 0; @@ -311,10 +308,9 @@ export function AppSidebar() { const selectedHistoryRunId = useTrainingRuntimeStore((s) => s.selectedHistoryRunId); const setSelectedHistoryRunId = useTrainingRuntimeStore((s) => s.setSelectedHistoryRunId); - // Recompute the bottom-fade state on mount and whenever the list height can - // change (items load, sections collapse/expand, route switches the visible - // list) - onScroll never fires for short, non-scrolling lists. Guarded - // setState below means this can't loop even if a dep is a fresh reference. + // Recompute bottom-fade on mount and whenever list height can change + // (items load, sections toggle, route switch) - onScroll never fires for + // short, non-scrolling lists. Guarded setState below can't loop. useEffect(() => { const el = scrollRef.current; if (!el) return; @@ -761,9 +757,8 @@ export function AppSidebar() { label={t("shell.navigation.search")} active={false} onClick={() => { - // Search is read-only over chat history and never runs - // inference, so it stays available while training (unlike - // New chat, which is gated on `chatDisabled`). + // Search is read-only and never runs inference, so it stays + // available while training (unlike New chat, gated on chatDisabled). useChatSearchStore.getState().open(); closeMobileIfOpen(); }} @@ -796,8 +791,7 @@ export function AppSidebar() { closeMobileIfOpen(); }} /> - {/* Train has its own labelled section when expanded; surface it as - a plain icon here only while the sidebar is collapsed. */} + {/* Train has a labelled section when expanded; plain icon here only when collapsed. */} {runItems.map((run) => { - // An explicit sidebar selection wins. Otherwise highlight - // the active job only while the "Current Run" tab is the - // view - that covers a live run (it auto-switches there) and - // a just-finished/errored run you're still viewing, while - // keeping the Configure tab unhighlighted even though - // `activeJobId` stays pinned to the last job. + // Explicit selection wins. Otherwise highlight the active + // job only while the "Current Run" tab is the view, keeping + // the Configure tab unhighlighted even though activeJobId + // stays pinned to the last job. const isActiveRun = selectedHistoryRunId != null ? run.id === selectedHistoryRunId @@ -988,10 +980,9 @@ export function AppSidebar() { - {/* Fade above the profile box, shown only while there's more list below - the fold; at the very bottom (or for short lists) it fades out so the - last row shows fully (Gemini-style). `right-2` keeps it clear of the - 8px scrollbar gutter so the scrollbar isn't faded out. */} + {/* Fade above the profile box, shown only when there's more list below + the fold; at the bottom (or short lists) it fades so the last row + shows fully (Gemini-style). right-2 keeps it clear of the 8px scrollbar gutter. */}