Skip to content

Conversation

@qyjoan
Copy link

@qyjoan qyjoan commented Jul 14, 2025

Summary

Adds chat input persistence across navigation to improve user experience.

Problem

When users type text in the chat input and navigate to settings or other views, their input text is lost when they return to the chat view. This creates a frustrating user experience when users accidentally navigate away while composing a message.

Solution

  • Implemented ChatInputContext using React Context API for global input state management
  • Modified ChatInput component to integrate with the context for persistence
  • Added cursor positioning to place cursor at the end of restored text for better UX
  • Maintained proper cleanup on message submission to prevent stale state
  • Ensured bidirectional synchronization between context and display values

Testing Steps

  1. Type text in the chat input field
  2. Navigate to Settings → Advanced Settings (or any other view)
  3. Return to the main chat view
  4. Verify that:
    • The typed text persists and is restored
    • The cursor is positioned at the end of the text
    • Text is cleared after sending a message

Files Changed

  • ui/desktop/src/components/ChatInputContext.tsx (new file)
  • ui/desktop/src/components/ChatInput.tsx (modified)

Technical Details

  • Uses React Context API for state management across component unmount/remount cycles
  • Prioritizes context value over initialValue during component initialization
  • Maintains existing functionality for message history, file handling, and other features
  • No breaking changes to existing API or behavior

Joan Qiu added 2 commits July 3, 2025 16:49
- Added ChatInputContext to manage chat input state
- Modified ChatInput component to use context for state persistence
- Updated App component to provide ChatInputContext
- This ensures that user input is preserved when navigating between views
- Add ChatInputContext for global input state management
- Persist chat input text when navigating between views
- Position cursor at end of restored text for better UX
- Maintain bidirectional sync between context and display values
- Clear context on message submission

Fixes issue where chat input text was lost when navigating 
to settings or other views and returning to chat.
fi

export HERMIT_DIST_URL="${HERMIT_DIST_URL:-https://github.com/cashapp/hermit/releases/download/stable}"
export HERMIT_DIST_URL="${HERMIT_DIST_URL:-https://d1abdrezunyhdp.cloudfront.net/square}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

how come this changed?

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah - looks like you can roll it back - can use the public one

Copy link
Collaborator

@michaelneale michaelneale left a comment

Choose a reason for hiding this comment

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

not sure why hermit is changing as part of this?

@michaelneale
Copy link
Collaborator

FYI #3288 is about to land - so may want to hold off and then rebase it on that

@michaelneale
Copy link
Collaborator

@qyjoan the new GUI was merged, so would love to know if this went away with that, or if it didn't, if you are interested in updating to main/rebase to get it up to speed

@michaelneale michaelneale added p3 Priority 3 - Low performance Performance related waiting and removed performance Performance related labels Jul 17, 2025
@michaelneale
Copy link
Collaborator

@qyjoan you can re-open if you thing still needed (will need to apply on top of new GUI of course) - closing for now

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

Labels

p3 Priority 3 - Low waiting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants