Skip to content

ChatInputBox: Persist draft messages across page navigation #646

Description

@ambient-code-stage

Summary

Users lose their in-progress draft messages when navigating away from a session page. This creates friction and frustration, especially when users are composing longer prompts.

Current Behavior

  • Draft text in the chat input box is lost when:
    • Navigating to another page (e.g., projects list, settings)
    • Switching between sessions
    • Refreshing the page
  • The down arrow currently only navigates through sent message history and queued messages

Proposed Behavior

  1. Auto-save drafts to localStorage - Persist draft content per-session so users can navigate away and return without losing work
  2. Down arrow restores draft - When at the bottom of message history (index -1), pressing down arrow should restore the current draft if one exists
  3. Clear draft on send - Remove the persisted draft when a message is successfully sent

Implementation Notes

Key file: components/frontend/src/components/chat/ChatInputBox.tsx

The component already has:

  • draftInput state for temporary draft storage during history navigation (line 204)
  • History navigation with up/down arrows (lines 332-367)
  • combinedHistory for queued + sent messages

Suggested approach:

  1. Create a custom hook useDraftPersistence(sessionId) that:

    • Reads draft from localStorage on mount
    • Debounces writes to localStorage on input change
    • Clears draft on send
    • Uses session-scoped key: draft:${sessionId}
  2. Update the down arrow handler to restore persisted draft when:

    • historyIndex is already at -1 (current input)
    • A persisted draft exists
    • Current input is empty
  3. Consider draft expiration (e.g., 7 days) to prevent localStorage bloat

Acceptance Criteria

  • Drafts persist when navigating away from a session
  • Drafts persist when refreshing the page
  • Down arrow at bottom of history restores draft if current input is empty
  • Drafts are cleared after successful message send
  • Drafts are scoped per-session (different sessions have different drafts)
  • Old drafts are cleaned up after expiration period

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ambient-code:auto-fixAmber agent: automated low-risk fixes (formatting, linting)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions