Repository navigation
Ask before leaving a page while typed words wait unsaved - #6467
Merged
Merged
Conversation
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_
leaf-agent
approved these changes
Nov 19, 2026
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]>
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.
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:runtimeand the drafts browser tests that reload or leave pages pass.