Skip to content

fix(drafts): stop clearing drafts on workspace switch and hide sent section#1708

Merged
wpfleger96 merged 3 commits into
mainfrom
wpfleger96/drafts-workspace-sent-fixes
Jul 10, 2026
Merged

fix(drafts): stop clearing drafts on workspace switch and hide sent section#1708
wpfleger96 merged 3 commits into
mainfrom
wpfleger96/drafts-workspace-sent-fixes

Conversation

@wpfleger96

@wpfleger96 wpfleger96 commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Three fixes on one branch: workspace-switch draft loss, sent-section display, and sent-record eviction.

Bug 1 — workspace switch clears drafts

resetWorkspaceState() called clearAllDrafts() which set currentPubkey to "" before cleanup effects flushed. When the draft store's flushStore ran during component teardown, it bailed early on if (!currentPubkey) return, so the draft was written to the empty-string localStorage bucket instead of the correct pubkey bucket. When initDraftStore(newPubkey) ran afterward it read the correct bucket — but the draft wasn't there.

Fix: remove the clearAllDrafts() call from resetWorkspaceState() in useWorkspaceInit.ts. initDraftStore(newPubkey) already resets _memCache and sets the new pubkey via its if (currentPubkey !== pubkey) guard — the double-clear was the bug.

Bug 2 — "Sent" section shows all sent messages

readDraftSections() in DraftsPanel.tsx rendered a "Sent" section populated by getSentDraftEntries(). Since markDraftSentEntry writes 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

markDraftSentEntry was still writing invisible sent: records into the same MAX_DRAFTS = 100 eviction pool as active drafts. Enough sends could silently evict older active drafts the user still expected to see.

Fix: replace markDraftSentEntry's body with clearDraftEntry(draftKey) — it now just clears the active draft and writes nothing. Callers (useMentionSendFlow) are unchanged. The _sentSeq counter is removed as dead code.

Migration: isValidDraftState now normalises stored status: "sent" entries to "active" so old sent records written by prior builds resurface in the Drafts panel instead of remaining permanently hidden. The getSentDraftEntries and markDraftSentEntry exports are kept intact for API compatibility.

The E2E test asserting the Sent heading and its associated fixtures are also removed.

@wpfleger96 wpfleger96 requested a review from a team as a code owner July 10, 2026 14:28
npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 and others added 3 commits July 10, 2026 11:19
…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>
@wpfleger96 wpfleger96 force-pushed the wpfleger96/drafts-workspace-sent-fixes branch from 28bc73b to 759b1fa Compare July 10, 2026 15:19
@wpfleger96 wpfleger96 merged commit e2d104f into main Jul 10, 2026
45 of 47 checks passed
@wpfleger96 wpfleger96 deleted the wpfleger96/drafts-workspace-sent-fixes branch July 10, 2026 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant