Skip to content

fix(agent-chat): preserve draft text when pane splits#140

Open
justinchoo93 wants to merge 1 commit intomainfrom
justin/preserve-chat-draft
Open

fix(agent-chat): preserve draft text when pane splits#140
justinchoo93 wants to merge 1 commit intomainfrom
justin/preserve-chat-draft

Conversation

@justinchoo93
Copy link
Collaborator

Summary

  • Pane splits restructure the React component tree, causing ChatComposer to unmount/remount and lose typed text from useState
  • Add a module-level Map<paneId, string> draft store (src/lib/draft-store.ts) that survives React lifecycle — ChatComposer reads from the store on mount and syncs on every keystroke
  • Drafts are cleaned up on pane close (PaneContainer) and tab close (tabsSlice)
  • Handles edge case where paneId prop changes in-place (resyncs text + textarea height)

Test plan

  • Unit tests for draft-store (get/set/clear, independent per paneId, empty string cleanup)
  • Unit tests for ChatComposer draft preservation (restore after remount, clear on send, independent per paneId, no-paneId fallback)
  • Manual: type text in a Freshclaude pane → split the pane → verify text is preserved
  • Manual: type text → send message → verify draft is cleared
  • Manual: close a pane with draft text → reopen → verify draft is not leaked

🤖 Generated with Claude Code

Pane splits restructure the React tree, causing ChatComposer to
unmount/remount and lose its useState text. Add a module-level
Map<paneId, string> draft store that survives React lifecycle.
ChatComposer reads from the store on mount and syncs on every
keystroke. Drafts are cleaned up when panes or tabs are closed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3e459bd2e5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines 214 to +215
if (content.kind === 'agent-chat') {
clearDraft(paneId)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Clear draft when closing panes after content replacement

This cleanup only runs when the pane is currently agent-chat, but drafts are keyed by paneId and survive content switches. If a user types a draft, replaces that pane with another kind via updatePaneContent, and then closes the pane, this branch is skipped and the old draft remains in the module-level map indefinitely. That creates a leak over repeated replace/close cycles and can surface stale text if that pane id is reused; draft cleanup should also happen on pane close by paneId regardless of current content or when replacing away from agent-chat.

Useful? React with 👍 / 👎.

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