Skip to content

fix(plugin-nested-docs): preserve published version when resaving children with drafts#15582

Draft
wingding12 wants to merge 1 commit intopayloadcms:mainfrom
wingding12:fix/nested-docs-resave-children-draft-version-loss
Draft

fix(plugin-nested-docs): preserve published version when resaving children with drafts#15582
wingding12 wants to merge 1 commit intopayloadcms:mainfrom
wingding12:fix/nested-docs-resave-children-draft-version-loss

Conversation

@wingding12
Copy link

Fixes #14943

What

Fixes child documents with drafts losing their published version when a parent document is saved.

Why

When a parent document is published, the resaveChildren hook updates all child documents to refresh breadcrumbs. When a child has both a published version and a newer draft version, both were updated sequentially. The second update (draft) caused createVersion to set latest = false on the just-created published version, making it inaccessible on the live site — the child page effectively disappeared.

How

Updated the resaveChildren hook to skip draft versions for children that also have a published version. Only the published version receives the breadcrumb update. Draft-only children (those that have never been published) continue to be updated normally.

This avoids the latest flag corruption without requiring changes to the core versioning logic in createVersion.

Testing

Added two integration tests to test/plugin-nested-docs/int.spec.ts:

  1. Published version preserved — creates a parent + published child, adds a draft edit to the child, re-publishes the parent, then verifies both the published and draft versions of the child remain accessible with correct breadcrumbs.
  2. Draft-only children still updated — creates a parent + draft-only child (never published), updates the parent, then verifies the draft child's breadcrumbs are refreshed.

…ldren with drafts

When a parent document is saved, the resaveChildren hook updates all
child documents to refresh their breadcrumbs. Previously, when a child
had both a published and a draft version, both were updated sequentially.
This caused createVersion to set `latest = false` on the published
version when the draft version was saved afterward, making the published
version inaccessible on the live site.

The fix skips draft versions for children that also have a published
version — only the published version receives the breadcrumb update.
Draft-only children (never published) continue to be updated normally.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

plugin-nested-docs: Child documents with drafts lose published version when parent is saved

1 participant