Repository navigation
Save a document as it is edited - #3
Merged
Merged
Conversation
A document that exists now writes itself once the typing pauses, for a signed-in user. Losing an afternoon's work because nobody pressed a button is not a state a document with a name and a home should be able to reach, and Save becomes a way to store the work *now* rather than the only way it is ever stored. Unsaved work is deliberately untouched: a draft has no id to write to and no owner to write it for, so `/` keeps its localStorage draft and its explicit Save, and signing in is still what turns one into the other. The two halves of a save had to be separated to do this. Content is a database row, so it is written on every pause; the preview behind it is a browser render against a quota shared with the PDF output, so a capture per pause would spend the quota the document's own output depends on. Saving now takes a `capturePreview` flag — absent means yes, so an explicit save behaves exactly as before — and the editor asks for the image separately, once the editing has actually stopped, through a new POST on the thumbnail route. That endpoint renders the *stored* document rather than content from the request, and does nothing when the current revision has already been captured, so a repeated request costs no browser time. The hook takes the live content rather than being handed it per call, which is what lets it act on its own; `stateFor(doc)` collapses into `state` now that it knows what is on screen. An existing document starts out already saved, so opening one no longer looks like unwritten work — without that, every open would cost a write and clear the card's preview. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MTqa7LTmuJMFEmNohAka5n
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
htmlcsspdf | 9378806 | Commit Preview URL Branch Preview URL |
Aug 31 2026, 08:55 PM |
File drops landed on main and touched the same line in App.tsx: the editor now holds a toast alongside the save hook, which takes the live content. Both are kept. Drop's own note that "the save is still the user's to make" is no longer true of a stored document — dropping a file into one is written like any other edit — so it now says what stays true: the undo history is the way back, and undoing is written back the same way. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MTqa7LTmuJMFEmNohAka5n
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.
A named document — one that exists at
/d/:id, for a signed-in user — now writes itself once the typing pauses. Save becomes a way to store the work now, not the only way it is ever stored.Unsaved work is deliberately untouched. A draft has no id to write to and no owner to write it for, so
/keeps its localStorage draft and its explicit Save, and signing in is still what turns a draft into a document.Pacing, and why the preview moved
Auto-save forced the two halves of a save apart. Content is a database row, so it is written on every pause (1.5s). The preview image behind it is a Browser Run session against a quota shared with the PDF output — a capture per pause in typing would spend the quota the document's own output depends on.
So:
PUT /api/documents/:idtakes acapturePreviewflag. Absent means yes, so an explicit save and document creation behave exactly as before; auto-save writes quietly.POST /api/documents/:id/thumbnailis new: it renders the stored document (never content from the request, which would let a caller put any image on a card) and does nothing when the current revision already has a capture, so a repeated request costs no browser time.Between a quiet write and the capture that follows it, the card shows "No preview" — the same honest placeholder it already shows for a failed or missing capture.
Hook changes
useDocumentSavenow takes the live content instead of being handed it per call, which is what lets it act on its own.stateFor(doc)collapses intostate. An existing document starts out already saved, so opening one is not mistaken for unwritten work — without that, every open would cost a write and clear the card's preview.A write in flight is never overlapped: when it lands,
savedContentchanges and the effect re-runs against the content as it is then, so anything typed during the request is picked up rather than written from a stale closure. A failed write retries on the next edit rather than immediately, and the button reads "Retry save" in the meantime.Merged with main
File drops landed on main and touched the same line in
App.tsx(the editor holds a toast beside the save hook); both are kept. Drop's own note that "the save is still the user's to make" is no longer true of a stored document, so it now says what stays true — the undo history is the way back, and undoing is written back the same way.Testing
bun run test(194 passing),tsc --noEmit,biome checkandbun run buildall run clean on the merged tree.src/server/documents.test.tsstill fails to load —node:sqlitecannot be bundled under this vite environment. Verified identical onmainin a clean worktree; untouched by this branch.Not covered: closing the tab inside the 1.5s debounce still loses that last edit. Flushing on
pagehideis a separate, self-contained change.