Skip to content

Commit 50e7c24

Browse files
authored
fix(plugin-nested-docs): publishing parent doc should not publish child doc (#9958)
## Bug Fix ### Issue Draft children documents get overwritten when the parent document is published. ### Fix Correctly retrieve all documents, including drafts, during the resave process. Add test to ensure parent documents can be published without impacting the state of any children docs.
1 parent 796df37 commit 50e7c24

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

packages/plugin-nested-docs/src/hooks/resaveChildren.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ type ResaveArgs = {
2323
const resave = async ({ collection, doc, draft, pluginConfig, req }: ResaveArgs) => {
2424
const parentSlug = pluginConfig?.parentFieldSlug || 'parent'
2525
const parentDocIsPublished = doc._status === 'published'
26-
2726
const children = await req.payload.find({
2827
collection: collection.slug,
2928
depth: 0,
30-
draft,
29+
draft: true,
3130
locale: req.locale,
3231
req,
3332
where: {

test/plugin-nested-docs/e2e.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,5 +136,18 @@ describe('Nested Docs Plugin', () => {
136136
// TODO: add back when error states are fixed
137137
// await expect(parentSlugInChild).toHaveValue('/parent-slug-draft')
138138
})
139+
140+
test('Publishing parent doc should not publish child', async () => {
141+
await page.goto(url.edit(childId))
142+
await page.locator(slugClass).nth(0).fill('child-updated-draft')
143+
await page.locator(draftButtonClass).nth(0).click()
144+
145+
await page.goto(url.edit(parentId))
146+
await page.locator(slugClass).nth(0).fill('parent-updated-published')
147+
await page.locator(publishButtonClass).nth(0).click()
148+
149+
await page.goto(url.edit(childId))
150+
await expect(page.locator(slugClass).nth(0)).toHaveValue('child-updated-draft')
151+
})
139152
})
140153
})

0 commit comments

Comments
 (0)