fix(desktop): preserve chat drafts per-pane in v2 workspace
Problem
Two related bugs in the v2 workspace chat:
- Drafts lost on tab switch — typing in the chat composer and switching tabs discarded the text.
- Drafts bleed across panes — two chat panes shared the same draft; typing in one replaced the other.
Root cause
The v2 WorkspaceChatInterface read a persisted draft on mount (initialInput={initialLaunchConfig?.draftInput}) but had no save-on-unmount logic — the v1 DraftSaver (PR #2631) was never ported.
The deeper cause is in packages/panes: Workspace.tsx renders only the active tab as <Tab tab={activeTab}> with no key. When two tabs each hold a chat pane at the same layout slot, React reconciles them into the same ChatPaneInterface → PromptInputProvider instance instead of remounting. Since useState(initialInput) only runs on first mount, the editor text never resets:
- Both panes session-less → text bleeds across panes (bug #2).
- Different sessions → the session-change clear effect wipes the editor (bug #1).
Because the instance is reused, unmount/remount-based persistence never engaged.
Fix
- Port v1's
DraftSaverpattern into v2: save the textarea draft to the pane'slaunchConfig.draftInputon unmount (guarded byisSendingRefso an in-flight send isn't re-persisted), and clear it on send and on session change. Threaded a newonSaveDraftcallback throughusePaneRegistry→ChatPane→ChatPaneInterface, wired to the pane registry'supdateData. - Key the chat pane by
ctx.pane.idinusePaneRegistryso switching between chat tabs cleanly remounts the chat subtree instead of reusing one instance. Scoped to chat on purpose — keying<Tab>itself would remount terminals/browsers, which intentionally persist. - Added
draftInputto v2'sChatPaneData.launchConfigtype (its inline type lacked it).
Testing
bun run typecheck→ passbun run lint→ pass- Manual: not yet run in the Electron app.
Summary by cubic
Preserves chat drafts per pane in the v2 workspace so drafts aren’t lost on tab switch or shared across chat panes. Users can switch tabs without losing what they typed.
- Bug Fixes
- Ported v1 DraftSaver to v2: save textarea draft on unmount to
launchConfig.draftInput, clear on send and on session change (guarded byisSendingRef). - Keyed chat panes by
pane.idin the registry to remount the chat subtree when switching tabs, preventing state bleed across panes; scoped to chat only. - Added
draftInputtoChatPaneData.launchConfigand threadedonSaveDraftthrough the registry →ChatPane→ChatPaneInterfaceto persist drafts.
- Ported v1 DraftSaver to v2: save textarea draft on unmount to
Summary by CodeRabbit
- New Features
- Chat message drafts now automatically persist when switching between tabs and conversations, ensuring your unsent messages are saved and restored when you return to a chat session.