Repository navigation
Restore of a Discard keeps the draft of a created document - #1737
Merged
haowjy merged 6 commits intoNov 17, 2026
Merged
Conversation
…n Trash or not in Live After Un-Apply of a created document, Live holds no blocks while the draft's base holds an empty one, and the text-changed check read that as a writer's edit. Nobody types into a document that is in Trash or not in Live yet, so its draft always reopens.
haowjy
marked this pull request as ready for review
November 17, 2026 00:40
…a left-out draft's Un-Apply editedSince read a base holding one empty paragraph against an empty Live as an edit; it now reads an empty document as no blocks, as blocksEqual does, and the Trash guard is gone. A draft that Restore leaves out now replays its waiting Un-Applies, so its Apply records stop claiming an Apply that was taken back.
The replay no longer flips the draft active, which tripped the one-active-draft index when a newer draft of the document sat on the same branch. appendRows takes draft: "any". The replica now installs after the Restore commits.
transfer() already waits for the commit through install; the extra deferral and rollback hook were redundant. The guarantee is stated once on PreparedDraftWrite.transfer.
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.
Changelog
Why
A Draft-mode chat creates
). A longer sequence (Apply, Undo, Apply all, Ctrl+Z in the Live document, Discard all, Undo discard) read "Not restored" while the chat's card said "Applied".
manuscript://Third; the writer applies it, presses the card's Undo, then Discard all and the row's "Undo discard". Nobody typed, yet the row read "Partly restored: 1 change couldn't come back" and opening it showed a blank draft (Cause: the Un-Apply of a create sends the Live document to Trash and reverses its text, leaving Live with no blocks. The draft's base holds one empty paragraph.
editedSince(drizzle-reopen-drafts.ts) diffs the base against Live, reads that as Live deleting the paragraph the change sits in, and leaves the draft out. A left-out draft stays closed, so opening it shows Live's empty text, which is the blank editor. The card read Applied next to a left-out row because a Restore that leaves a draft out never finished the draft's waiting Un-Apply: the draft kept its Apply record, which the card reads as applied.Examples
Restore a created document after Un-Apply
MODEL_PROVIDER=mock pnpm dev; a Work in Draft mode; mock scriptwrite create manuscript://Fifth.Real typing on an existing document still leaves the change out
Benchmarks
None. One indexed lookup by document id on Restore of a Discard, which is not a hot path.
Design decisions
editedSincediffed the base against Live withdiffBlocks, which reads no blocks and one empty paragraph as different, whileblocksEqual(used by the Live pull) reads both as an empty document. It now turns an empty base or Live into no blocks before diffing, so created, deleted, trashed and standing documents follow one rule. An earlier version of this PR skipped the check for a document in Trash or without a tree row; that is gone, and a standing document with the same shape (base one empty paragraph, Live none) restores too.appendRowstakesdraft: "any", likework: "any"), so the draft is never flipped active, and a newer active draft of the same document on its branch cannot collide with it.Changes
editedSince; left-out drafts replay their waiting Un-Appliesdrizzle-reopen-drafts.tsCompatibility and risk
left_out.emptyAsNoneineditedSince, and the left-out branch at the top ofreopen.Verification
agent-browseragainstpnpm devon this branch, mock provider. The three steps above restore the row with no "Partly restored", and opening it shows "Quiet dusk." (left_outwith no error and the Apply record is gone.pnpm test:dbon the apply-restore file passes.pnpm check.Deferred
None.
References
findings/prober-1555.md.editedSince's approx-hunk handling.collab/.context/apply.md.