Repository navigation
perf(chat): load the chat timeline and LegendList as their own chunk - #977
Conversation
The chat timeline (and @legendapp/list under it) was a static import of ChatView, so it sat in the entry chunk. It now loads through components/chatTimelineLoader.ts: the import starts when the entry runs, and a conversation read waits for it before setting any turn, so the list mounts once with ChatView's refs bound. Until it arrives ChatView draws the same loading state without the list. ChatTimeline.css stays in the entry because .chat-frame and the loading state need it first. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 19 minutes. View limit details
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Summary
Merge Risk: ⚪ Minimal · up to
|
Problem
After #951 the entry chunk grew from about 475 KB to about 572 KB gzip. Part of that is
@legendapp/list, whichChatTimelinepulls in, andChatTimelinewas a static import ofChatView. So every page load parsed the list library, even for someone who never opens the chat lens.Root cause
ChatView.tsxdidimport { ChatTimeline } from "./ChatTimeline.tsx", andChatViewis a static import ofPaneTerminal. That put the timeline and@legendapp/listin the entry chunk.The list is only about 42 KB of the roughly 97 KB #951 added. The rest is React 19 and the other #951 code. This PR does not touch that.
Change
src/components/chatTimelineLoader.ts. It runsimport("./ChatTimeline.tsx")once, when the entry runs, so the chunk is fetched right after the entry and not when chat is opened. It keeps the loaded component and exposesuseChatTimeline()(auseSyncExternalStore). If the load fails, the loader forgets it so the next read tries again. It does not useReact.lazy, because that can suspend once even when the module has already loaded.ChatView's conversation read waits for the chunk (await loadChatTimeline()) before it sets any turn. Once the chunk has loaded, this check costs nothing. Because of the wait, the list never mounts with a partly loaded conversation: it mounts once, withscrollerandtimelinebound, and the restore, initial scroll-to-end andonReadeffects see the list.ChatViewshows the same loading state (header, then the "Loading conversation…" footer) inside the same.chat-view.chat-view-virtual/.chat-transcript-virtualboxes, just without the list. The two effects that bind the scroll node once (ResizeObserverfollow anddismissKeyboardOn) now depend on the loaded component too, so they bind to the list's node when it mounts.ChatTimeline.cssis still imported fromChatView, so it stays in the entry CSS..chat-frame,.chat-frame-bodyand the loading state need it before the chunk arrives, so no styles change late.src/AGENTS.md(Chat lens row) describes the split.Trade-off: the entry gets smaller, so there is less to parse and compile before first paint. The total bytes of a cold load stay the same, because the chunk is fetched right away and not on demand. If the chunk cannot be fetched (offline after an update, for example), the chat error line shows the browser's "Failed to fetch dynamically imported module" text, and the next poll tries again. The other lazy viewers (RepoDiff, VirtualSource) already behave this way. The service worker caches every hashed
/assets/file, so the new chunk is cached like the others.Measurements
bun run build. Before isorigin/main9dce921, after is this branch.index-*.jsraw.js.gzserved.js.brservedChatTimeline-*.jsLegendListno longer appears in the entry chunk. No CSS chunk was split off.Validation
Linux x64, Bun 1.4.3.
bun run check fast: all steps ok (typecheck, build, unit tests 3455 pass / 0 fail).CI=1 bun run check run --build bun scripts/ui-regression.ts,... scripts/chat-fallback-browser-qa.tsand... scripts/chat-virtual-browser-qa.ts.LegendListwas held. While it was held: the chunk was a separate request, the conversation read had happened, "Loading conversation…" showed, there were no turn rows, and.chat-framewasposition: absolute. After the chunk was released: rows rendered, the view sat at the end (row 199 visible), and after the viewport was narrowed the view was still at the end, so theResizeObserverwas bound to the list's node.🤖 Generated with Claude Code