fix: Prevent chat overwrite during loading phase#199
Conversation
- Expose isPending state from useChatSession hook - Include isPending in isStreaming prop to disable input during chat loading - Prevents users from accidentally overwriting chats while they're still loading Fixes #198 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Anthony <AnthonyRonning@users.noreply.github.com>
WalkthroughThe chat session hook’s return value is expanded to include an isPending flag. The chat route consumes this new flag and includes it in the ChatBox isStreaming condition. No other logic, control flow, or error handling changes are introduced. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant ChatComponent
participant useChatSession
participant ChatBox
User->>ChatComponent: Open chat / interact
ChatComponent->>useChatSession: Invoke hook
useChatSession-->>ChatComponent: { streamingError, isPending, ... }
ChatComponent->>ChatBox: isStreaming = loading || persisting || summarizing || isPending
ChatBox-->>User: Show streaming/pending UI state
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Assessment against linked issues
Possibly related PRs
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. 📜 Recent review detailsConfiguration used: CodeRabbit UI 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (2)
🧰 Additional context used📓 Path-based instructions (2)**/*.{ts,tsx,js,jsx}📄 CodeRabbit Inference Engine (CLAUDE.md)
Files:
**/*.{ts,tsx}📄 CodeRabbit Inference Engine (CLAUDE.md)
Files:
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
🔇 Additional comments (3)
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Greptile Summary
This PR fixes a critical data loss bug where users could accidentally overwrite entire chat histories by typing messages while chats were still loading from the server. The issue occurred because the chat input remained enabled during the loading phase, allowing users to submit messages before the full chat data was retrieved, which would initialize the optimistic state with an empty messages array and overwrite the existing chat.
The fix involves two key changes:
-
Exposing
isPendingstate: TheuseChatSessionhook now returns theisPendingstate from React Query'suseQuery, which indicates when chat data is still being fetched from the server. -
Disabling input during loading: The chat component now includes
isPendingin theisStreamingprop calculation (isLoading || isPersisting || isSummarizing || isPending), which disables the chat input during all phases where the chat state might be unstable.
This change integrates seamlessly with the existing architecture, leveraging React Query's built-in loading states and the component's existing input disabling mechanism. The hook already had a guard clause (if (!serverChat || isPending) return;) that prevents optimistic updates during loading, and now the UI properly reflects this loading state by disabling user input. This prevents the race condition where user input could overwrite partially loaded chat data, particularly important for users with long chat histories.
Confidence score: 5/5
- This PR is safe to merge with minimal risk as it addresses a critical data loss bug with a targeted fix
- Score reflects the use of existing React Query patterns and proper integration with the component's input disabling mechanism
- No files require special attention as the changes are straightforward and leverage existing architectural patterns
2 files reviewed, no comments
Fixes issue where users could overwrite chats while they're still loading.
Changes
isPendingstate from useChatSession hookisPendinginisStreamingprop to disable input during chat loadingCloses #198
Generated with Claude Code
Summary by CodeRabbit