Skip to content

Ask before leaving a page while typed words wait unsaved - #6467

Merged
max-sixty merged 2 commits into
mainfrom
keep-both-drafts
Nov 19, 2026
Merged

max-sixty merged 2 commits into
mainfrom
keep-both-drafts

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Words typed while the page's server was out of reach, or on an exported page, stayed in the tab until a write got through, and closing the tab or leaving the page lost them silently. Leaving now asks first, through the browser's own prompt, whenever a draft holds words the server hasn't taken and no write is carrying, so the user decides whether they still want them. Words a write is carrying need no prompt, since the page's going away sends them again.

To weigh: this asks rather than keeps. Keeping the words in the browser past the tab was built twice, in #6221 and again on a branch today; each time a late replay brought back words sent, cancelled or written over elsewhere, and five rounds of review kept finding more. A safe replay needs the store to know every write it ever took (each tab numbering its writes, the store keeping the highest number per tab), estimated at 130–180 lines and a protocol bump. A reload also prompts while words wait, since the prompt can't tell it from a close, though the tab's reload keeps them.

max-sixty asked for Leaf to keep typed work, simply and robustly.

Tests: a runtime test that leaving asks while a write has failed and not once one lands, which fails without the change; checked by hand in Chromium and Firefox that a reload prompts while draft writes are refused and doesn't once the server has the words. pnpm run check, pnpm run test:runtime and the drafts browser tests that reload or leave pages pass.

This was written by Claude Code on behalf of max-sixty

Words typed while the page's server was out of reach, or on an exported page, stayed
in the tab until a write got through, and closing the tab or leaving the page lost
them without a word. Leaving now asks first, through the browser's own prompt,
whenever a draft holds words the server hasn't taken and no write is carrying, so
the user decides whether they still want them. Words a write is carrying need no
prompt, since the page's going away sends them again.

Keeping those words in the browser past the tab instead was built twice, in #6221
and again on a branch today. Each time, a replay arriving late brought back words
sent, cancelled or written over elsewhere, and review kept finding more such cases;
a safe replay needs the store to know every write it ever took.

A reload asks too, since the prompt can't tell it from a close, though the tab's
reload keeps the words. Checked in Chromium and Firefox that a reload prompts while
writes are refused and doesn't once the server has the words.

New: a runtime test that leaving asks while a write has failed and not once a write
lands.

> _This was written by Claude Code on behalf of max-sixty_
@max-sixty
max-sixty merged commit 2e39fbb into main Nov 19, 2026
5 checks passed
@max-sixty
max-sixty deleted the keep-both-drafts branch November 19, 2026 05:18
leaf-agent added a commit that referenced this pull request Nov 19, 2026
…6490)

Leaving a page now asks first when a comment draft holds only a drawing
that no write has carried to the server. Before, the `beforeunload`
check that #6467 added counted only a draft's words. A user who drew on
a region and typed nothing, while the server was out of reach or on an
exported page, could close or reload the tab with no prompt and lose the
drawing. SOUL.md is the rule this breaks: "Leaf drops words the user
typed only when it knows they no longer want them".

`browser/runtime/drafts.js` already counted a drawing as content in two
places: the drafts list (`listDraft`) and `giveBackWords`. All three now
read one predicate, `holdsWork`, so they can't drift apart again.
`draftHasContent` answers a different question and is unchanged.

There is one small change in `giveBackWords`: it used to test
`current.text` untrimmed, and it now trims. So a draft holding only
whitespace no longer counts as its own work, and the given-back payload
replaces it.

**Verification:** a new runtime test in `tests/runtime/drafts.test.mjs`,
at the same boundary as #6467's test for words. Leaving asks while a
drawing-only `composer:` draft waits with draft writes failing, and
stops asking once a write lands. It fails without the change. `pnpm run
check` passes.

---------

Co-authored-by: leaf-agent <[email protected]>
Co-authored-by: Claude <[email protected]>
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.

2 participants