fix(ui): keep unsent composer drafts per conversation - #34
Open
CatJuly wants to merge 1 commit into
Open
Conversation
Typing in one session's composer and switching to another task threw
the text away in both directions: parents remount the composer with
`key={channelId}` on session switches, and a channelId effect
additionally reset the text to '' on every change. Users lost whatever
they had typed the moment they glanced at another task.
Keep unsent drafts in a module-level map keyed by channel id — the
convention chat products follow, where a draft belongs to its
conversation. Every keystroke writes through to the map, mounting or
switching restores the current channel's draft instead of wiping it,
and a successful send clears the entry. Attachments intentionally
still reset on switch: their object URLs and upload state are tied to
the current mount.
Verified with `npm run typecheck` and `npm run build`; manually typed
in session A, switched to B (empty composer, no cross-talk), typed in
B, switched back and forth — both drafts restored; sending cleared the
draft for that session only.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
With multiple task sessions open, typing into one session's composer and then switching to another task discards the draft — in both sessions. Whatever the user had typed is simply gone.
Repro: open two task sessions → type into session A's composer without sending → click session B in the sidebar → switch back to A. The composer is empty in both A and B.
Root cause
Two independent paths throw the text away on a session switch:
ContextPanelmounts the composer withkey={channelId}, so switching sessions unmounts and recreates the component — andtextlives in plainuseState('').MessageComposeradditionally has achannelIdeffect that explicitly resets the text to''on every change, so even a non-remounting switch wipes it.Neither path saves the draft anywhere first.
Fix
Follow the convention chat products use: a draft belongs to its conversation.
Map<channelId, string>(survives thekey-driven remounts).Attachments intentionally still reset on switch: their object URLs and upload state are tied to the current mount, and preserving them would leak resources.
Testing
npm run typecheck— cleannpm run build— clean; rebuiltfrontend_distbundle includedScope
Frontend only (
MessageComposer.tsx+ rebuilt dist). Independent of my other open PRs — no shared files.