fix: Prevent draft autosave state loss and editor overwriting#283
fix: Prevent draft autosave state loss and editor overwriting#283orrc wants to merge 3 commits intoemdash-cms:mainfrom
Conversation
Revision-backed autosaves were updating the draft revision but returning the base content row, so the API response could immediately disagree with the saved draft state. Reload the current draft revision after a successful save and merge its data and draft slug into the returned item. Add a regression test covering skipRevision updates on a revision-backed collection. Co-authored-by: Codex <codex@openai.com>
Update the admin autosave path so a PUT response is only applied back into the edit-page queries when the local editor state still matches the snapshot that was sent. This keeps autosave from triggering an extra GET for the same item, but avoids overwriting newer local edits with a stale response that arrives after the user keeps typing. Add focused regressions for the query-cache update helper and the ContentEditor snapshot guard. Co-authored-by: Codex <codex@openai.com>
Reconcile PortableTextEditor with post-mount value updates from parent state, while avoiding unnecessary resets for equivalent content. Add browser regressions covering external value replacement without onChange noise and preserving clean history for equivalent updates. Co-authored-by: Codex <codex@openai.com>
|
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
Overlapping PRsThis PR modifies files that are also changed by other open PRs:
This may cause merge conflicts or duplicated work. A maintainer will coordinate. |
What does this PR do?
Fixes a cluster of related draft/autosave bugs in the admin editor for revision-enabled content.
This started from a verified repro on a published post:
PUTresponse returned stale contentGETrequest also returned stale base-row dataRoot cause turned out to be three separate compounding issues:
packages/corePUTresponse was built from the stale base content row instead of the active draft revisionpackages/adminGETpackages/adminPortableTextEditortreated its initial value as mount-only stateWhat this PR changes:
GETcall from the client (as the necessary data is in the autosave response).Relates to #272, but extends beyond that admin-only reset loop to also fix the stale revision-backed autosave response, the redundant post-autosave refetch, and the in-flight autosave overwrite edge case.
Type of change
Checklist
pnpm typecheckpassespnpm --silent lint:json | jq '.diagnostics | length'returns 0pnpm testpasses (or targeted tests for my change)pnpm formathas been runAI-generated code disclosure
But with a lot of prior verification, including with Playwright, and a lot of discussion on the solution