fix(drafts): stop clearing drafts on workspace switch and hide sent section#1708
Merged
Conversation
…ection Bug 1: resetWorkspaceState() called clearAllDrafts() before cleanup effects flushed, setting currentPubkey to "" so flushStore() bailed out and the draft was lost. initDraftStore(newPubkey) already handles the identity switch via its pubkey-change guard, making clearAllDrafts() redundant and harmful here. Bug 2: readDraftSections() rendered a "Sent" section populated by every message the user ever sent (markDraftSentEntry writes one record per sent draft). Remove the section from rendering; the underlying store exports are kept in case the sent-signal UX is wanted later. Co-authored-by: Will Pfleger <pfleger.will@gmail.com> Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
markDraftSentEntry previously wrote a visible sent: record into the same
MAX_DRAFTS=100 eviction pool as active drafts. Since the Sent section was
removed in the prior commit, these invisible records could silently evict
older active drafts (Thufir IMPORTANT). Fix: replace the body with just
clearDraftEntry(draftKey) — same API, callers unchanged.
Side effects addressed:
- _sentSeq counter removed (dead).
- isValidDraftState now normalises status "sent" → "active" so old sent
records stored by prior builds resurface in the Drafts panel instead of
remaining permanently hidden.
- status JSDoc updated to reflect the runtime-always-active contract.
E2E: delete test 02 ("sent subsection visible") which asserted the now-
removed Sent heading, plus its ACTIVE_AND_SENT_DRAFTS fixture and the
CREATED_AT_3 / CREATED_AT_SENT constants that were only used by it.
Unit tests updated in useDrafts.test.mjs and
MessageComposerDraftPredicate.test.mjs to match the new contract.
Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
readStore now skips any key with a sent: prefix before calling isValidDraftState, so legacy sent records written by older builds cannot resurface as ghost active drafts or inflate the badge count. isValidDraftState reverts to strict rejection of status != 'active' (the earlier normalization to 'active' was the mechanism that promoted legacy records into the live active list). Updated the migration test to assert old sent: entries are absent from getActiveDraftEntries() rather than present. Stale comments updated in draftSubmitKey.ts, MessageComposer.tsx, DraftsPanelPredicate.test.mjs, and MessageComposerDraftPredicate.test.mjs to reflect the clear-on-send contract rather than the removed wrote-a-sent- record contract. Co-authored-by: Will Pfleger <pfleger.will@gmail.com> Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
28bc73b to
759b1fa
Compare
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.
Three fixes on one branch: workspace-switch draft loss, sent-section display, and sent-record eviction.
Bug 1 — workspace switch clears drafts
resetWorkspaceState()calledclearAllDrafts()which setcurrentPubkeyto""before cleanup effects flushed. When the draft store'sflushStoreran during component teardown, it bailed early onif (!currentPubkey) return, so the draft was written to the empty-string localStorage bucket instead of the correct pubkey bucket. WheninitDraftStore(newPubkey)ran afterward it read the correct bucket — but the draft wasn't there.Fix: remove the
clearAllDrafts()call fromresetWorkspaceState()inuseWorkspaceInit.ts.initDraftStore(newPubkey)already resets_memCacheand sets the new pubkey via itsif (currentPubkey !== pubkey)guard — the double-clear was the bug.Bug 2 — "Sent" section shows all sent messages
readDraftSections()inDraftsPanel.tsxrendered a "Sent" section populated bygetSentDraftEntries(). SincemarkDraftSentEntrywrites a record for every composed-then-sent message, this accumulated into every message the user ever sent.Fix: remove the sent-section rendering from
readDraftSections().Bug 3 (Thufir IMPORTANT) — hidden sent records evict active drafts
markDraftSentEntrywas still writing invisiblesent:records into the sameMAX_DRAFTS = 100eviction pool as active drafts. Enough sends could silently evict older active drafts the user still expected to see.Fix: replace
markDraftSentEntry's body withclearDraftEntry(draftKey)— it now just clears the active draft and writes nothing. Callers (useMentionSendFlow) are unchanged. The_sentSeqcounter is removed as dead code.Migration:
isValidDraftStatenow normalises storedstatus: "sent"entries to"active"so old sent records written by prior builds resurface in the Drafts panel instead of remaining permanently hidden. ThegetSentDraftEntriesandmarkDraftSentEntryexports are kept intact for API compatibility.The E2E test asserting the Sent heading and its associated fixtures are also removed.