Skip to content

[Bug]: Sidebar UI latency: hover-card lag, O(rows x drafts) New Thread scan, focusin DOM scan, and blocking settle-advance #41083

Done

Description

@royalaid

Area

apps/web

Steps to reproduce

  1. Run T3 Code with a workspace that has many mounted active/pinned/expanded sidebar threads (e.g. 50 to 200+ rows), multiple threads with large linked PR stacks (14 to 20+ PRs), and several draft sessions.
  2. Hover sweep: Move the pointer rapidly across multiple sidebar thread cards and PR badges.
  3. New Thread: Click "New Thread" from an active server thread (especially when defaultThreadEnvMode is unset / null and t3.json is cold or revalidating, or with multiple draft sessions present).
  4. Navigation: Click or keyboard-navigate between sidebar rows in a large thread list.
  5. Settle and advance: Settle the active thread (via button, keyboard shortcut, or drag-to-settle) so the app advances to the next eligible thread or a new draft.

Expected behavior

  • Sweeping the pointer across sidebar rows should cancel superseded hover targets instead of queuing lag or detaching the active popup from the pointer.
  • Clicking "New Thread" should transition promptly without O(rows x drafts) selector scans, full-list geometry reads on pure route changes, or cold t3.json RPC stalls.
  • Switching focus across rows in a large sidebar should remain responsive without full-DOM scans on each focusin.
  • Settling an eligible idle thread (where an optimistic settlement overlay is already applied) should advance immediately instead of blocking on the full thread.settle server RPC round-trip.

Actual behavior

Static inspection of main at c89ca0a2f2 (including locked @base-ui/[email protected]) identified four bottlenecks behind noticeable UI sluggishness in daily use. All file and line citations below are verified from source at c89ca0a2f2; per-frame Chromium runtime attribution is still pending a production trace.

1. Rapid sidebar hover / PR flyout lag (not fully covered by #39971)

  • 0 ms instant-open across adjacent rows: Both the main sidebar list (apps/web/src/components/Sidebar.tsx:3449-3454) and search results (Sidebar.tsx:3314-3319) use <TooltipProvider delay={150} closeDelay={0} timeout={400}>. Once any tooltip in the group opens, Base UI's FloatingDelayGroup puts subsequent sibling hovers into 0 ms instant-open mode (timeout={400}), so fast pointer sweeps across rich thread cards can open each crossed row's popup synchronously without a target-change dwell.
  • Unbounded visible-PR rendering and repeated chain derivation: ThreadPullRequestsMiniList (apps/web/src/components/ThreadStatusIndicators.tsx:492-560) renders every visible linked PR (after filtering stack-dismissed tombstones via visibleThreadPullRequests) with no item cap. (fix(web): sidebar thread hover card stays within the window with many PRs #39971 caps the row hover card to 5 lines, which helps height, but leaves repeated pre-filter derivation and instant-open sweep behavior unaddressed.) visibleThreadPullRequests (packages/shared/src/threadPullRequests.ts:4-8) allocates a fresh filtered array on every call, so multi-PR threads repeatedly filter, derive chains, and sort across useLinkedThreadPullRequest, resolveThreadPullRequestBadge, and ThreadPullRequestsMiniList (packages/source-control-core/src/shared/threadPullRequests.ts:151, 193, 290, 369).
  • Outer tooltip work on closed rows: While TooltipPortal keeps popup DOM descendants unmounted when closed, SidebarThreadTooltip (apps/web/src/components/sidebar/SidebarThreadRow.tsx:256-404) still executes its hooks and JSX construction on closed-row renders, and each row mounts multiple Base UI <Tooltip> roots (SidebarThreadRow.tsx:872-888, 1327, 1514, 1533, 1729; ThreadStatusIndicators.tsx:476). Extending apps/web/src/components/ui/shared-tooltip.tsx with a cancellable target-change dwell timer and lazy body render would avoid mounting/computing superseded hover cards during rapid sweeps.

2. Slow "New Thread" (1 to 2 seconds; partially overlaps #21479)

  • O(mounted rows x draft sessions) Zustand selector scan: Every mounted SidebarThreadRow subscribes to useThreadHasUnsentDraft(threadRef) (SidebarThreadRow.tsx:735), calling getComposerDraftState -> resolveComposerDraftKey (apps/web/src/composerDraftStore.ts:1609-1634, 1668-1677, 4749-4753). Whenever a server thread has no direct state.draftsByThreadKey[scopedKey] entry (the common case), resolveComposerDraftKey enumerates Object.entries(state.draftThreadsByThreadKey) to match environmentId and threadId (composerDraftStore.ts:1622-1629). Each draft-store notification runs this O(rows x drafts) scan synchronously across all mounted rows even when every selector returns false and React renders zero rows. A WeakMap<Record<string, DraftThreadState>, ReadonlyMap<string, string>> keyed on state.draftThreadsByThreadKey makes this O(1) per row.
  • Conditional pre-navigation readT3ProjectFile await: On the direct draft path (apps/web/src/hooks/useHandleNewThread.ts:202-234, 281-373, 408-460, t3ProjectFileDefaults.ts:11-28), when defaultThreadEnvMode === null, resolveDefaultEnvMode() awaits readT3ProjectFile (projectCommands.ts:103-107, staleTimeMs: 30_000, idleTtlMs: 5 min). perf(web): paint new-thread drafts from cached state #21479 addresses the landing page, but explicitly leaves other New Thread entry points on the blocking defaults flow.
  • Full-list geometry reads on draft route change: listMotionLayoutKey includes routeDraftIdForRows (Sidebar.tsx:2040-2063). Changing it triggers useLayoutEffect -> shiftGuardRef.current.update() (Sidebar.shiftGuard.ts:23-29, 110-126, reading offsetTop on every direct <ul> child) and listMotionRef.current.update(...) (Sidebar.motion.ts:127-147, reading offsetTop/offsetLeft/offsetWidth/offsetHeight on every eligible direct child). Keying listMotionLayoutKey on actual ordered rendered draft row IDs avoids full-list scans on pure route changes.
  • Server-to-draft ChatView unmount/remount: Switching between server threads keeps ChatView mounted, whereas navigating from a server thread to a new draft renders <ChatView key={target.draftId} ... routeKind="draft" /> (apps/web/src/components/ThreadRouteView.tsx:77-96, 169-225), unmounting and remounting ChatView (preserving handoffKey promotion continuity needs care if unified).

3. General sidebar navigation slowdown with large thread counts (related to #39933, #39934, #40893)

  • O(N) DOM query and filter on every row focusin: In apps/web/src/lib/sidebarTree.ts:19-26, 72-80, onFocus runs on every focusin that resolves to a sidebar row and calls visibleRows().indexOf(row), running root.querySelectorAll("[data-sidebar-row]") plus .closest('[hidden], [inert], [aria-hidden="true"]') and .matches(":disabled") across every mounted row to save focusedIndex.
  • Route-dependent subscriptions in Sidebar: Sidebar calls useHandleNewThread() (Sidebar.tsx:1004, 1014-1020, useHandleNewThread.ts:496-538), subscribing the sidebar shell to route target, active thread shell, and draft store state even though only the New Thread click handler needs them.

4. Slow settle-and-advance (2 to 5 seconds; tracked by open PR #27309)

  • Both attemptSettle (Sidebar.tsx:1654-1683, used by click, keyboard shortcut via useThreadLifecycle.tsx:710-720, multi-select at Sidebar.tsx:2521, and sweep at :1884-1888) and drag-to-settle (Sidebar.tsx:2214-2234) await settleThread(threadRef) before calling navigateAfterSettle?.(), even though threadEnvironment.settle (packages/client-runtime/src/state/threadCommands.ts:535-552) already applies an optimistic settlement overlay immediately for eligible idle threads. When no eligible next card exists in the ordered list, advancing calls handleNewThread (Sidebar.tsx:1642), compounding directly into Add open-in-editor feature with Cmd+O shortcut #2.
  • Open PR fix(web): settling the open thread advances immediately #27309 already proposes advancing immediately on settle/snooze.

Related issues and PRs

Impact

Major degradation or frequent failure

Version or commit

main @ c89ca0a

Environment

Windows 11, T3 Code desktop / web client (pingdotgg/t3code main at c89ca0a2f2)

Workaround

None for hover lag or settle-advance blocking; keeping active/expanded sidebar thread counts and draft counts low reduces #2 and #3.

Activity

  1. royalaid commented on Nov 22, 2026

    @royalaid
    Author

    Opened PR #41102 (perf(web): fix sidebar hover lag, slow New Thread, and settle navigation wait) with fixes and regression tests for all four symptoms reported here:

    • Sidebar hover & PR flyout lag: Shared lazy <SharedTooltipProvider> with cancellable open/switch dwell, scroll dismissal via <TooltipScrollDismissArea>, WeakMap-cached PR stack derivation in threadPullRequests.ts, and an 8-item hover preview cap with +N more expansion.
    • Slow New Thread clicks: WeakMap reverse index for draft sessions in composerDraftStore.ts, prefetched t3.json with a synchronous fast path for fresh/optimistic reads (and explicit refresh/retry on stale or failed prefetches), and click-time New Thread context resolution.
    • Large-sidebar navigation: Cached visible row index map in sidebarTree.ts with structural-only invalidation (zero DOM scans on non-row content updates while preserving focus restoration on row removal and inline rename dismissal).
    • Settle-to-next delay: Unified optimistic advance across click, shortcut, batch, and drag settlement once the local settlement overlay applies, with error reporting on failure and success-only Undo.

    Validated locally with vp check (0 errors), 3-package typecheck, React Compiler coverage, 187 targeted unit + Chromium browser tests, and a live parallel T3 Code instance against an isolated snapshot of a 1,177-thread database.

  2. juliusmarminge commented on Dec 1, 2026

    @juliusmarminge
    Member

    #46827, now on main: Repeated sidebar and hover-preview PR chain derivation and sorting now reuse cached results for unchanged linked-PR arrays, including arrays containing dismissed stack links.

    Not done: The issue also asks for cancellable hover dwell and lazy tooltip work, faster New Thread creation, fewer sidebar focus and layout scans, and immediate settle-and-advance; this merge does not implement those changes.

    Closing; open a new issue if what is left still matters to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions