Skip to content

fix(web): drafts survive a second tab, a thread switch mid-paste, and empty files - #1026

Merged
badcuban merged 3 commits into
mainfrom
fix/draft-followups
Nov 20, 2026
Merged

badcuban merged 3 commits into
mainfrom
fix/draft-followups

Conversation

@badcuban

Copy link
Copy Markdown
Collaborator

Three ways a message draft could lose text or files, found while reviewing the Device panel (#1010):

  • Two tabs. Every tab kept its own copy of all drafts and wrote all of them to one storage entry. So a tab could write its old copy over a draft another tab had changed, sent or cleared. Starting a new thread in one tab could also delete a draft the other tab had just typed into.
  • Switching threads mid-paste. The composer cancelled an attachment save when its thread changed. A file still being read when you switched threads was never saved, and it was gone after a reload.
  • Empty files. A zero-byte attachment saves as a data URL with nothing after the comma. Reading drafts back treated that as broken and dropped the file.

How it's fixed

  • Two tabs.
    • Each draft write now also leaves a small writer stamp (threadlines:composer-drafts:v1:writer). Before writing, a tab reads that stamp, which is a few bytes.
    • Once the stamp shows another tab wrote, every later write from this tab reads storage first and changes only the drafts this tab changed since its last write. It finds those through the store's own object identity, so there's no extra serializing.
    • A draft this tab removes as empty during cleanup keeps its stored copy if the other tab has typed into it.
    • With one tab open, nothing large is read and the cost is unchanged.
    • Two tabs changing the same draft is the one case left: the last write wins for that draft.
    • The merge lives in an opt-in option on createDebouncedJSONStorage; other stores using it are unchanged.
  • Thread switch. The attachment save is no longer cancelled. It finishes for the thread it started in. A run that a newer change made stale (a send, a removal, another paste) still writes nothing.
  • Empty files. A saved attachment with size 0 and a real data: URL comes back as an empty file. A broken record is still rejected.

Checked

  • Each fix has a browser test using the browser's real local storage, and each test fails with its fix removed:
    • another tab's change kept
    • a filled draft kept through cleanup
    • a paste saved after its composer unmounted mid-read
    • an empty file back after a reload, with a broken record still rejected
  • vp fmt, vp lint and vp run typecheck are clean.
  • Web unit tests pass: 3,328.
  • Web browser tests pass: 1,157 of 1,158. The one timing test that failed under load passes when run alone.
  • Reviewed independently. Its findings that held were fixed here: a write racing the other tab's notice, cleanup deleting a filled draft, and a malformed empty record.

Left as is

  • A file pasted while storage is full stays unsaved after space frees up. That's already how main behaves; this PR doesn't change it.

… empty files

Every tab wrote its whole copy of all drafts to one storage key, so a tab
could write its stale copy over a draft another tab had changed. Once
another tab writes the key, each write now keeps every draft this tab did
not change as storage has it; with one tab open nothing extra is read.

The composer cancelled an attachment save when its thread changed, so a
paste still being read when the user switched threads was never saved.
The save now finishes for the thread it started in; a run made stale by a
newer change already writes nothing.

An empty file saves as a data URL with no payload, and reading drafts back
dropped it; it now comes back as an empty file.
…ver deletes a draft filled elsewhere

Each draft write leaves a small writer stamp; a tab reads it before writing
instead of waiting for the storage event, so a write that races another
tab's still merges. A draft this tab removes as empty keeps the stored copy
if another tab has typed into it. An empty saved file must be a real data
URL to come back.
@vercel

vercel Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
threadlines Skipped Skipped Nov 20, 2026 7:55pm UTC

Request Review

@badcuban
badcuban added this pull request to the merge queue Nov 20, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 20, 2026
@badcuban
badcuban added this pull request to the merge queue Nov 20, 2026
Merged via the queue into main with commit 8808b6a Nov 20, 2026
32 of 34 checks passed
@badcuban
badcuban deleted the fix/draft-followups branch November 20, 2026 20:25

This branch was previously deployed

1 inactive deployment
Preview — e47450c2 Deployed Nov 20, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant