Skip to content

Conversation

@qdaxb
Copy link
Contributor

@qdaxb qdaxb commented Jul 1, 2025

Related GitHub Issue

Closes: #5306

Description

Save the content to localStorage regularly to avoid permanent loss of the text being entered

Test Procedure

  • Enter text
  • Restart the plugin
  • The previous text should still be displayed in the input box

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

Documentation Updates

Additional Notes

Get in Touch


Important

Adds chat draft persistence using localStorage with a new useChatTextDraft hook in ChatTextArea.tsx.

  • Behavior:
    • Implements chat draft persistence using localStorage in ChatTextArea.tsx.
    • Introduces useChatTextDraft hook to auto-save drafts every 5 seconds, restore on mount, and clear on send.
    • Replaces onSend with handleSendAndClearDraft to clear drafts after sending.
  • Functions:
    • useChatTextDraft: Manages draft lifecycle with localStorage.
    • handleSendAndClearDraft: Clears draft and calls onSend.
  • Misc:
    • Adds import for useChatTextDraft in ChatTextArea.tsx.

This description was created by Ellipsis for c307066c1a00412f8209162e6f674186e6b4cf7a. You can customize this summary. It will automatically update as commits are pushed.

@qdaxb qdaxb requested review from cte, jr and mrubens as code owners July 1, 2025 11:18
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Jul 1, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 1, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jul 1, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Jul 1, 2025
Copy link
Member

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

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

Hey @qdaxb, Thank you for your contribution!

I left some suggestions that are worth taking a look at, let me know if you have any questions!

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Changes Requested] in Roo Code Roadmap Jul 1, 2025
@daniel-lxs daniel-lxs moved this from PR [Changes Requested] to PR [Needs Prelim Review] in Roo Code Roadmap Jul 1, 2025
@daniel-lxs
Copy link
Member

I did some research on using localStorage with VS Code extensions, and it seems the general consensus is that it's better to use the ExtensionContext and choose between globalState or workspaceState, depending on the use case.

Roo Code doesn't use localStorage except in very specific cases, so I think it makes sense to follow that pattern for this draft implementation as well.

Curious to hear what you think!

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Changes Requested] in Roo Code Roadmap Jul 1, 2025
@qdaxb qdaxb force-pushed the support_chat_draft branch from e47d7f2 to 7babbb1 Compare July 2, 2025 04:19
@qdaxb
Copy link
Contributor Author

qdaxb commented Jul 2, 2025

I did some research on using localStorage with VS Code extensions, and it seems the general consensus is that it's better to use the ExtensionContext and choose between globalState or workspaceState, depending on the use case.

Roo Code doesn't use localStorage except in very specific cases, so I think it makes sense to follow that pattern for this draft implementation as well.

Curious to hear what you think!

I think this makes the implementation a bit more complex, but considering future maintenance costs, it’s acceptable.
I’ve already made the changes according to the ExtensionContext approach.

@daniel-lxs daniel-lxs moved this from PR [Changes Requested] to PR [Needs Prelim Review] in Roo Code Roadmap Jul 7, 2025
@qdaxb qdaxb force-pushed the support_chat_draft branch from 7babbb1 to 9b0ae78 Compare July 7, 2025 16:43
Copy link
Member

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

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

Hey @qdaxb, I left a couple of suggestions that are worth taking a look at. Let me know if you have any questions!

const handleDraftValue = (event: MessageEvent) => {
const msg = event.data
if (msg && msg.type === "chatTextDraftValue") {
if (typeof msg.text === "string" && msg.text && !inputValue) {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a potential race condition here? The draft is only restored if !inputValue, but what happens if the component receives an initial value before the message handler is set up? Could we miss restoring a valid draft in that case?

debounceTimerRef.current = setTimeout(() => {
try {
// Fast pre-check: if character count is much greater than max bytes, skip encoding
if (inputValue.length > MAX_DRAFT_BYTES * 2) {
Copy link
Member

Choose a reason for hiding this comment

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

The pre-check using inputValue.length > MAX_DRAFT_BYTES * 2 might be too conservative. For strings with many multi-byte characters (like emojis or non-Latin scripts), this could reject valid drafts prematurely. Would it make sense to adjust this heuristic or document why 2x was chosen?

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Changes Requested] in Roo Code Roadmap Jul 8, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 22, 2025
@github-project-automation github-project-automation bot moved this from PR [Changes Requested] to Done in Roo Code Roadmap Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request PR - Changes Requested size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

support saving draft of chat message

3 participants