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
🚀 Deploying Preview to Cloudflare 🚀Preview URL: https://fix-publish-autosave-race.try.emdashcms.com, https://fix-publish-autosave-race-emdash-playground.emdash-cms.workers.dev (commit 1445e7c)This URL reflects your latest Preview deploymentPreview Deployments by commit
|
@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
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