From edd08156803e62f31832cd69cab857b485df2e5b Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 9 Apr 2026 11:52:13 -0700 Subject: [PATCH 1/9] Extract ChatComposer to fix composer keystroke re-renders MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Typing in the composer caused the entire ChatView (~4900 lines) to re-render on every keystroke because `useComposerThreadDraft` subscribed to the full draft including `prompt`. This cascaded to MessagesTimeline, ChatHeader, BranchToolbar, PlanSidebar, and terminal drawers. - Extract `ChatComposer` (memo'd) that owns the prompt/images/terminal context store subscriptions, all composer-local state, and derived values (menu items, provider state, send state, debounced queries). ChatView now uses granular store selectors for only `runtimeMode`, `interactionMode`, and `activeProvider` — none of which change on keystroke. - Extract `ExpandedImageDialog` (memo'd) for the image preview modal. - Wrap `BranchToolbar` in `memo` and stabilize `onRevertUserMessage` with `useCallback` so already-memo'd children (MessagesTimeline, ChatHeader) properly skip re-renders. - Expose `ChatComposerHandle` for cross-cutting operations (focus, cursor reset, terminal context insertion, send context). Co-Authored-By: Claude Opus 4.6 (1M context) --- apps/web/index.html | 1 + apps/web/src/components/BranchToolbar.tsx | 6 +- apps/web/src/components/ChatView.tsx | 1771 ++-------------- apps/web/src/components/chat/ChatComposer.tsx | 1806 +++++++++++++++++ .../components/chat/ExpandedImageDialog.tsx | 122 ++ 5 files changed, 2084 insertions(+), 1622 deletions(-) create mode 100644 apps/web/src/components/chat/ChatComposer.tsx create mode 100644 apps/web/src/components/chat/ExpandedImageDialog.tsx diff --git a/apps/web/index.html b/apps/web/index.html index 9f0329b602..a0149eba6d 100644 --- a/apps/web/index.html +++ b/apps/web/index.html @@ -8,6 +8,7 @@ +