fix(plugin-nested-docs): preserve published version when resaving children with drafts#15582
Draft
wingding12 wants to merge 1 commit intopayloadcms:mainfrom
Draft
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
resaveChildrenhook 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) causedcreateVersionto setlatest = falseon the just-created published version, making it inaccessible on the live site — the child page effectively disappeared.How
Updated the
resaveChildrenhook 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
latestflag corruption without requiring changes to the core versioning logic increateVersion.Testing
Added two integration tests to
test/plugin-nested-docs/int.spec.ts: