fix: keep a sending home draft in the workspace it was sent from

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Guilhem Lemouel
2026-10-30 05:59:59 -07:00
co-authored by Claude Opus 5.5
parent 086ffadb9f
commit 4959f8ae5d
2 changed files with 22 additions and 3 deletions
@@ -1080,12 +1080,13 @@ if (BROWSER) {
// Home's draft acts on the workspace the page header names, so a switch to another
// workspace of its family takes the draft along. A switch to another family leaves
// it where it was: Home shows that family's own draft. Not a touch, so the draft's
// last activity stays when the user last worked on it.
// it where it was: Home shows that family's own draft. A draft already sending stays
// too: its send commits the workspace it started in, but only after the pre-flight.
// Not a touch, so the draft's last activity stays when the user last worked on it.
function followHomeDraft(): void {
const s = homeDraft.id ? sessionState.sessions.find((x) => x.id === homeDraft.id) : undefined
const ws = get(workspaceStore)
if (!s || !ws || s.workspace_id) return
if (!s || !ws || s.workspace_id || sendUnderWay(s.id)) return
if (s.pending_workspace_id === ws && !s.pending_fork) return
if (s.pending_workspace_id && workspaceRootId(ws, get(userWorkspaces)) !== sessionRootId(s)) {
return
@@ -735,6 +735,24 @@ describe('homeStarterSession', () => {
}
})
it('keeps a draft whose first send is under way in the workspace it was sent from', () => {
const restore = withTwoFamilies('forkA')
sessionState.sessions.push(session({ id: 'sending-draft', pending_workspace_id: 'forkA' }))
const sendingNow = () => sessionState.sessions.find((s) => s.id === 'sending-draft')
try {
holdHomeDraft('sending-draft')
setSendUnderWayCheck((id) => id === 'sending-draft')
workspaceStore.set('rootA')
holdHomeDraft('sending-draft')
expect(sendingNow()?.pending_workspace_id).toBe('forkA')
} finally {
setSendUnderWayCheck(() => false)
homeDraft.id = undefined
sessionState.sessions = sessionState.sessions.filter((s) => s.id !== 'sending-draft')
restore()
}
})
it('lets go of its blank once a hand-off reuses it for an item', () => {
const restore = withTwoFamilies('forkA')
const prevCurrent = sessionState.currentSessionId