Skip to content

fix(ui): preserve published content when restoring drafts - #18394

Merged
jacobsfletch merged 3 commits into
payloadcms:mainfrom
PINYOPATTANAWASANPORN:fix/ui-restore-draft-version-as-draft-18389
Oct 21, 2026
Merged

jacobsfletch merged 3 commits into
payloadcms:mainfrom
PINYOPATTANAWASANPORN:fix/ui-restore-draft-version-as-draft-18389

Conversation

@PINYOPATTANAWASANPORN

@PINYOPATTANAWASANPORN PINYOPATTANAWASANPORN commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Restoring a draft version could overwrite and unpublish the live document.

  1. Draft versions don't expose the Restore as draft menu option.
  2. The primary restore action defaults to draft: false, so restoring a draft writes its content and status to the live document.

The fix is to restore draft versions with draft: true and label the primary action Restore as draft.

Adds an e2e regression verifying that draft content is restored while newer published content and status remain unchanged.

Fixes #18389.

@jacobsfletch jacobsfletch changed the title fix(ui): restore draft version as draft when collection has drafts enabled (#18389) fix(ui): preserve published content when restoring drafts Oct 21, 2026
@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: de1c97f4-a86b-42b0-9496-d9b8252c5c09
📥 Commits

Reviewing files that changed from the base of the PR and between 58e4024 and 2dc17de.

📒 Files selected for processing: 2
  • packages/ui/src/views/Version/Restore/index.tsx
  • test/versions/e2e.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

The restore view now selects draft restoration when the selected version is a draft and collection drafts are enabled. An end-to-end test verifies that restoring a historical draft leaves the published document unchanged.

Changes: Draft version restore

Layer / File(s) Summary
Select and verify draft restoration
packages/ui/src/views/Version/Restore/index.tsx, test/versions/e2e.spec.ts
The restore action initializes draft mode based on the version status and labels the action accordingly. Canceling resets draft mode. The end-to-end test checks that draft API reads return the restored historical content while live reads retain the published content.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 2dc17

Draft restoration is covered by a test of the primary action, with the published document remaining unchanged. No merge-blocking issue was identified.

Security architecture risk: 🔵 Low · up to 2dc17

The restore action now selects the existing draft-only write path, preserving published content without changing server-side authorization. No introduced security issue was established. Remaining uncertainty concerns the browser test’s request identity and failure or concurrent execution behavior.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed action affects restoration of a selected collection version into its parent document’s draft workspace. It does not introduce a new cross-service authority path: the server resolves the parent from stored version data and applies update authorization before persistence.

Trust Boundaries and Controls

  • observed — The client-selected draft flag is not an authorization grant. The endpoint does not request an access override. The operation defaults overrideAccess to false, evaluates access.update with the request, parent ID and effective status, and combines returned document constraints into the parent lookup. Existing integration tests separately cover publication and unpublication denials with an explicit user.

Resilience and Maintainability Implications

  • inferred — Reinitializing mode on each action and resetting it on cancellation reduces selection leakage between modal openings. Repeated or concurrent requests still use the existing restore operation; their ordering and interruption behavior were not demonstrated by the added normal-execution test.
Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main fix: preserving published content when restoring drafts.
Description check Passed The description directly explains the draft restoration bug, the UI fix, and the end-to-end regression test.
Linked Issues check Passed The changes satisfy the coding requirements in #18389. packages/ui/src/views/Version/Restore/index.tsx restores a draft version with draft=true, labels the primary action version:restoreAsDraft,…
Out of Scope Changes check Passed The changed UI code implements the requested collection restore behavior. The end-to-end test directly verifies the regression fix. No unrelated change is identified. The linked issue's global restore…
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Full details: Linked Issues check

Explanation

The changes satisfy the coding requirements in #18389. packages/ui/src/views/Version/Restore/index.tsx restores a draft version with draft=true, labels the primary action version:restoreAsDraft, and resets draft state when the modal opens or is cancelled and when restore actions run. test/versions/e2e.spec.ts verifies that the restored draft remains separate from the published document and that published content remains available.

Full details: Out of Scope Changes check

Explanation

The changed UI code implements the requested collection restore behavior. The end-to-end test directly verifies the regression fix. No unrelated change is identified. The linked issue's global restore observation is not required because the stated PR scope targets the collection UI.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Git: CodeRabbit could not clone the repository, so clone-backed analysis was skipped and this review may be incomplete. Verify repository clone access, such as SSH credentials, before requesting another full review. If clone access is intentionally unavailable, use path_filters to narrow the review scope.

Comment @coderabbitai help to get the list of available commands.

@jacobsfletch jacobsfletch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! I added an e2e regression test and tightened up the PR title and description a bit.

Moving forward, we're considering making Restore as draft the standard for all version restores when drafts are enabled. See #18892.

@jacobsfletch
jacobsfletch enabled auto-merge (squash) October 21, 2026 15:47
@jacobsfletch
jacobsfletch merged commit 4859c0b into payloadcms:main Oct 21, 2026
575 of 599 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🚀 This is included in version v4.0.0-beta.4

jacobsfletch pushed a commit that referenced this pull request Nov 16, 2026
Identical to #18394, back-ported for 3.x.

Co-authored-by: Maarten Behr <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restoring a Draft version in the admin unpublishes the live document

2 participants