Repository navigation
fix(admin): save editor state before publishing - #2860
Conversation
🦋 Changeset detectedLatest commit: 1445e7c The changes in this PR will be included in the next version bump. This PR includes changesets to release 17 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Scope checkThis PR changes 585 lines across 5 files. Large PRs are harder to review and more likely to be closed without review. If this scope is intentional, no action needed. A maintainer will review it. If not, please consider splitting this into smaller PRs. See CONTRIBUTING.md for contribution guidelines. |
2d8e696 to
a6afada
Compare
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/auth-atproto
@emdash-cms/blocks
@emdash-cms/cloudflare
@emdash-cms/contentful-to-portable-text
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/plugin-cli
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/registry-moderation
@emdash-cms/registry-verification
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-field-kit
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
There was a problem hiding this comment.
The approach is sound. The PR fixes the publish/autosave race by serializing editor saves/autosaves through a single promise queue, making the publish handler first flush the current editor payload, and threading _rev tokens through save and publish so a failed/conflicting flush stops the publish. That builds cleanly on the revision-token work already in the server and router.
I checked the diff, the server publish handler (packages/core/src/api/handlers/content.ts), the publish route (packages/core/src/astro/routes/api/content/[collection]/[id]/publish.ts), existing ContentEditor and router tests, and the component call-sites for onPublish. The server already supports _rev in publish, the tests cover the serialization cases, and the ContentEditor/ContentSettingsPanel prop wiring is consistent.
Two issues keep this from being a clean sign-off:
-
Optimistic
lastSavedDataupdate inContentEditor.handlePublishcan mark the wrong state as saved. The router coalesces repeated Publish clicks by returning the same in-flight promise. The editor captures a freshsavedStatefor each click and applies it when the promise resolves. The second click’s payload may be discarded by the router, but the editor still setslastSavedDatato the second click’s saved state, so the editor can briefly (or persistently, depending on render ordering) believe unsaved changes are saved. -
Form submission bypasses the disabled Save button during publish.
handleSubmitdoes not check the sameisContentSaveBlockedcondition that disablesSaveButton. That means pressingEnterin an input while a publish flush/publish is in flight can queue a second save, re-dirtying the form after the publish completes.
Both are small fixes in packages/admin/src/components/ContentEditor.tsx.
The changeset is accurate and user-facing.
a6afada to
1445e7c
Compare
…sending a refused token (#2902) * fix(admin): let the editor recover from a save conflict instead of resending a refused token The first refused save left the rejected revision token from #2860 in place, so every later save and autosave resent it and the writer could not get their work in at all. The editor now takes the server's current token when a save comes back as a conflict, and suspends autosave for that entry until the writer decides. Without the suspension the queued autosave writes over the other version as soon as the token is refreshed, which is the silent overwrite the token was added to prevent. When the recovery read fails there is no newer version to offer, so the notice goes and the save error is reported rather than swallowed. Discarding the draft takes the notice down as well. * fix(admin): keep the conflict notice until the save it offers starts The Save anyway action cleared the notice and then called submitSave, which returns early when a save is in flight, a URL field is invalid, or an unsupported Portable Text mark is present. On that path the writer lost the banner without a save being attempted. Worse than losing the affordance: the recovery read has already refreshed the revision token, so clearing hasSaveConflict also lifts the autosave block. The next keystroke autosaves against the fresh token and succeeds, overwriting the other writer silently, which is what the suspension exists to prevent. The action now only saves. Both content mutations already clear conflictedEntryId in onSuccess, so the notice goes when the save is confirmed and stays whenever it is not. That leaves onDismissSaveConflict without a caller, so it is removed.
What does this PR do?
Makes Publish save and await the editor's exact current payload before promoting a draft. Editor saves and autosaves share a serialized queue, so an in-flight autosave completes before the publish flush, and the pending debounce is cancelled so it cannot replay older state afterward.
This builds on the editor revision-token work merged in #2121 and the lifecycle preconditions merged in #2783. The route advances its current
_revafter each save and publish response, so a validation error, failed save, or revision conflict stops the publish request, while repeated Publish clicks share the same in-flight operation.Closes #2123
Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (complete@emdash-cms/adminsuite: 1,805 tests)pnpm formathas been run (focused oxfmt formatting and check for changed files)AI-generated code disclosure
Screenshots / test output
Screenshots are not applicable because the rendered interface is unchanged.
pnpm --filter @emdash-cms/admin test: 142 files and 1,805 tests passedpnpm --filter @emdash-cms/admin build: passedpnpm typecheck: passed across 34 workspace projectspnpm lint: passed with warnings deniedpnpm --silent lint:json | jq '.diagnostics | length':0git diff --check: passed