-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: preserve unsent chat input across reloads #8237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Add chatDraft field to GlobalState type in global-settings.ts - Implement draft saving/loading in ChatView component with 500ms debounce - Add message handlers for draft persistence in webviewMessageHandler - Add new WebviewMessage and ExtensionMessage types for draft operations - Clear draft when task starts to avoid interference - Persist both text and images in draft Fixes #8236
| | "editQueuedMessage" | ||
| | "dismissUpsell" | ||
| | "getDismissedUpsells" | ||
| | "persistDraft" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an inconsistency in the naming of these message types: the new key is persistDraft (without the 'ed'), whereas the subsequent keys use Persisted (i.e. clearPersistedDraft and requestPersistedDraft). Consider aligning these so that the naming is consistent (e.g., either use persistDraft consistently or update it to persistedDraft).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewing my own code is like proofreading my own typos - I'll probably miss something obvious.
| text: inputValue, | ||
| images: selectedImages, | ||
| }) | ||
| }, 500) // Debounce for 500ms |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential memory leak: This useEffect creates a new timeout on every inputValue or selectedImages change but only cleans up the last one. If the user types quickly, multiple timeouts could accumulate.
Consider using a ref to track the timeout or a proper debounce hook.
| // Load persisted draft on mount | ||
| useEffect(() => { | ||
| // Request the persisted draft from the extension | ||
| vscode.postMessage({ type: "requestPersistedDraft" }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Race condition risk: There's no guarantee the extension will respond before the user starts typing, potentially overwriting their input with an older draft.
Consider adding a flag to prevent overwriting if the user has already started typing.
| text: inputValue, | ||
| images: selectedImages, | ||
| }) | ||
| }, 500) // Debounce for 500ms |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoded magic number: Consider extracting this debounce delay as a named constant for better maintainability: const DRAFT_SAVE_DEBOUNCE_MS = 500;
| } | ||
| case "persistDraft": { | ||
| // Save the draft to global state | ||
| await updateGlobalState("chatDraft", { text: message.text || "", images: message.images || [] }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing error handling: These draft persistence operations should have try-catch blocks to handle potential failures gracefully.
Fixes #8236
Summary
This PR implements chat draft persistence to prevent loss of unsent messages when VS Code reloads or the extension crashes.
Changes
chatDraftfield to GlobalState type for storing draft dataImplementation Details
Testing
Review Notes
The implementation received a 95% confidence score in automated review with the following assessment:
Future Improvements
Important
Adds chat draft persistence to prevent loss of unsent messages across VS Code reloads, with changes in state management, message handling, and UI components.
chatDraftfield toGlobalStateinglobal-settings.tsfor storing unsent chat inputs.ChatViewinChatView.tsxwith a 500ms debounce.persistDraft,clearPersistedDraft, andrequestPersistedDraftinwebviewMessageHandler.ts.persistDraft,clearPersistedDraft, andrequestPersistedDrafttoWebviewMessageandExtensionMessagetypes.This description was created by
for aebd78e. You can customize this summary. It will automatically update as commits are pushed.