fix(web): flush pending raw-markdown on unload (BUG-2024)#883
Merged
Conversation
…dirty prompt (BUG-2024)
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.
BUG-2024 — Raw-markdown editor loses typed content on tab close/reload
From the PLAN-1984 Web-UX audit: up to ~1.2s of typed raw-markdown content is lost on tab close/reload. The item-detail
beforeunloadhandler only flushed the collaborative (Yjs) path and ignored pending raw markdown debounced edits, and never warned on dirty state.Before
items.content.onBeforeUnloadflushed only the collab Y.Doc snapshot — the pending raw edit (rawPendingMarkdown) was silently dropped.After
onBeforeUnloadstill flushes the collab path unchanged, and now additionally, when raw markdown is dirty (rawPendingMarkdown !== null):PATCH /items/{id}of the pending content so the request survives page teardown (keepalive: true, the modernsendBeaconequivalent; markdown bodies are well under the ~64KB cap).event.preventDefault()+event.returnValueso the browser shows its native "unsaved changes" prompt — only when actually dirty, never on a clean page.rawPendingMarkdown+ the dirty flag once the keepalive save lands, so if the user picks "Stay" a later unload doesn't re-prompt / re-PATCH already-saved content.rawPendingMarkdownis the authoritative dirty signal — set on every raw keystroke, cleared tonullafter each normal debounced save. So the prompt only fires when there's genuinely unsaved content.client.ts
api.items.updategains an optional{ keepalive?: boolean }— passed straight tofetch(mirrors the existingflushCollabContentkeepalive option). No behavior change for existing callers.Test plan
npm run check— 0 errors (only pre-existing unrelated warnings)npm run build— succeedsnpm run test— 138/138 passrawPendingMarkdown !== null; dirty cleared after normal save (existing path) and after keepalive save; collab flush preserved untouched.Refs BUG-2024, PLAN-1984.