Repository navigation
fix(blog): stop overlapping autosaves from dropping the penultimate edit - #7147
Merged
Merged
Conversation
Debounced block autosaves (post/record/category/redirect editors) debounce at 700ms but the write lands in ~2s, so rapid edits overlap. Two concurrency gaps combined to silently drop an earlier edit: - Writes weren't serialized: overlapping saves raced their optimistic cache writes, and an earlier save finishing last re-applied its older payload over a newer one. Serialize per-branch via `scope.id`. - The `useAutosave` re-seed guard only covered the debounce-timer window, so a slow save's older echo reverted the draft mid-flight; the next edit then built on the reverted draft, losing the penultimate edit. Guard the re-seed on an in-flight save (`isSaving`) too, wired from `save.isPending`. Adds use-autosave.test.tsx covering the in-flight-echo guard, the pending guard, settled re-seed, and sync. Co-Authored-By: Claude Opus 4.8 <[email protected]>
decocms Bot
pushed a commit
that referenced
this pull request
Sep 10, 2026
PR: #7147 fix(blog): stop overlapping autosaves from dropping the penultimate edit Bump type: patch - decocms (apps/api/package.json): 4.351.1 -> 4.351.2 - @decocms/native (apps/native/package.json): 4.351.1 -> 4.351.2 Deploy-Scope: web
aka-sacci-ccr
pushed a commit
that referenced
this pull request
Sep 11, 2026
One conflict, in the post editor, and it was the interesting kind: both sides had rewritten the same header. The restructure moved the header block below a floating expand/close cluster; upstream changed what's inside it. Kept the restructure's layout and applied upstream's two behaviour changes into it, because taking either side whole would have silently dropped a fix: - #7152 ungated "See preview" from `hasErrors`. The restructure's copy still had `disabled={!previewUrl || hasErrors}`, which is the bug that PR fixes, so the gate is gone and the title no longer branches on it. - #7147 gave `useAutosave` an `isSaving` option so overlapping autosaves stop dropping the penultimate edit. Threaded through, keeping `buildPostBlock` and the three-value destructure the restructure needs for `syncPost` on a block rename. #7150's preview-route fix needed nothing here: the call site is identical on both sides and the change lives in `buildBlogPostPreviewUrl`. Co-Authored-By: Claude Opus 5 (1M context) <[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.
Summary
Fixes a data-loss bug reported by a content team: while uploading content in the blog editors, editing rapidly (an edit every ~1–2s) would intermittently lose the penultimate edit, which then had to be redone. The workaround was waiting 3–4s between edits.
The block editors autosave with a 700ms debounce, but the write lands in ~2s (network + coalesced commit), so consecutive edits produce overlapping saves. Two concurrency gaps combined to drop an earlier edit:
use-save-block.ts). Overlapping saves raced their optimisticonMutate/onSuccesswrites into the shared decofile cache, and an earlier save finishing last re-applied its older payload over a newer one — permanent loss when responses land out of order. (In cms/FastPreview modepatchDecofilereturns only the draft pointer, so the content cache is driven purely by these optimistic writes.)useAutosavere-seed guard was too narrow (use-autosave.ts). It wasif (!pending)— only the debounce-timer window. During the ~2s save-in-flight windowpendingis false, so a slow earlier save's echo (older payload landing back in the cache) didsetDraft(older), reverting the draft; the user's next edit then built on the reverted draft, omitting the penultimate edit permanently.Changes
scope: { id }inuseSaveBlock, so saves run one at a time in edit order — payloads stack and the last write always wins. Backend commits already coalesce per branch, so no correctness cost.useAutosavesignature(initial, save, delay?)→(initial, save, opts?: { delay?, isSaving? }); re-seed is nowif (!pending && !isSaving). All four editors (post/record/category/redirect) pass{ isSaving: save.isPending }.isPendingstays true across a serialized burst until the last save settles, so the draft can't be transiently reverted mid-burst.Testing
use-autosave.test.tsx(renderHook) covering the in-flight-echo guard, the pending guard, settled re-seed, andsync.bun testblog suite (213 tests) ✅,bun run check(typecheck) ✅,bun run lint(0 errors) ✅,bun run fmt✅.Affected areas
Blog block editors (post, category, author/record, redirect) — the manual content-editing flow. No schema/API changes.
🤖 Generated with Claude Code
Summary by cubic
Fixes the blog editors silently dropping the penultimate edit when typing every 1–2 seconds, caused by overlapping autosaves where a slower earlier save could land after a newer one and overwrite it.
Bug Fixes
scope: { id }inuseSaveBlockso saves apply in edit order.useAutosave's re-seed on in-flight saves in addition to the debounce timer, so a slow save's older echo can't revert the draft mid-edit; all four editors passsave.isPendingasisSaving.use-autosave.test.tsxcovering the in-flight echo, pending, settled re-seed, and sync paths.Written for commit 5a75b20. Summary will update on new commits.