Skip to content

Make agent tab switches render from cache - #47

Merged
srctl merged 1 commit into
mainfrom
claude/fast-tab-switching
Nov 19, 2026
Merged

srctl merged 1 commit into
mainfrom
claude/fast-tab-switching

Conversation

@srctl

@srctl srctl commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Requested by Scott · project thread

Why

Switching between an agent's Chat, Note and Dashboard tabs felt slow, almost like a server render. It's a client-side navigation, but:

  1. Each tab is its own route, and the first visit to a tab blocks on its server loader before anything changes on screen. Loader data was also dropped after 5 minutes, so tabs went cold again.
  2. Chat and Dashboard remount the conversation, then re-render every message ~10 times in the first few hundred ms (scroll bookkeeping, localStorage reads, the 1 s poll) because the message list wasn't memoized. The poll kept doing that every second afterwards.

Server time is not the problem: the loaders take 25–90 ms on the 4.5 GB dev database.

What changed

  • AgentHeader preloads its sibling tabs 250 ms after mount, so a click or tap renders from the router cache and revalidates in the background (works on touch, unlike hover prefetch).
  • Router keeps loader and preload data for 30 minutes (defaultGcTime, defaultPreloadGcTime) instead of 5.
  • Conversation messages render through a memoized ConversationRow with stable react/openReply handlers, so unchanged messages skip re-rendering on polls and state updates.
  • NoteWorkspace keeps its first snapshot and refreshes once on mount, so cached or background-reloaded loader data can't re-trigger draft recovery and stale cached notes catch up immediately.

Measurements

Production build of main vs this branch on the dev data copy (Shoppy, 60 rendered messages), headless Chrome, median of 4 switches.

Before After
First visit to Note, 100 ms network latency (click → painted) 176 ms 76 ms
First visit to Dashboard, 100 ms latency 174 ms 63 ms
Main-thread work per Chat switch, 4× CPU throttle 166 ms 95 ms
Main-thread work per Dashboard switch, 4× CPU throttle 153 ms 99 ms

Testing

  • pnpm test (429 pass), tsc --noEmit, biome check.
  • Browser smoke test on the production build: tab round trips, reaction popover opens, "Reply in thread" opens the thread, no console errors.

🤖 Generated with Claude Code

Switching between Chat, Note and Dashboard waited on a server loader the
first time each tab opened, and Chat/Dashboard then re-rendered every
message about ten times while the conversation settled.

- The agent header preloads its sibling tabs after mount, so a click or tap
  renders from the router cache and revalidates in the background.
- Keep loader data for 30 minutes so long stays on one tab still switch
  from cache.
- Memoize conversation rows with stable handlers, so polls and scroll
  bookkeeping no longer re-render unchanged messages.
- The note editor keeps its first snapshot and refreshes once on mount, so
  cached or background-reloaded data can't re-trigger draft recovery.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@srctl
srctl force-pushed the claude/fast-tab-switching branch from 662a9a2 to ce6913b Compare November 19, 2026 18:58
@srctl
srctl merged commit 222ad51 into main Nov 19, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant