Gutenberg: Draft child pages: parent is removed when an autosave is performed

Created on 18 Oct 2018  路  11Comments  路  Source: WordPress/gutenberg

Describe the bug
When publishing a page, that was a draft and also was assigned to have a parent page, the parent is removed when the child page is published.

To Reproduce
Steps to reproduce the behavior:

  1. Create a page in Gutenberg, publish it
  2. Create another page in Gutenberg, set it as child page of the page created above, save but do not publish
  3. Check on pages overview that the child page is correctly added below the parent page
  4. Add contents to child page
  5. Publish child page, it becomes a first level page, the parent page connection is removed

Expected behavior
When publishing a page that already has a parent page assigned, keep that structure.

Desktop (please complete the following information):

  • OS: macOS High Sierra
  • Browser: Firefox
  • Version: 62

Smartphone (please complete the following information):
not tested

Additional context

  • WordPress 4.9.8
  • Gutenberg 3.9.0
REST API Interaction [Status] In Progress [Type] Bug

All 11 comments

Hey @luminuu,
thanks for reporting this issue. I can also reproduce it with the current master.

I couldn't recreate this issue following the steps above. I could only get it to occur when when the parent page is made to be a draft after being published, not the child page.

Steps to recreate the issue:

  1. Create and publish a page.
  2. Create a second page and make it a child of Page 1. Either save as draft or publish it.
  3. Edit Page from step 1 and make it a draft.
  4. Open the child page. Parent Page Dropdown now has no items in it.
  5. Either saving the draft or publishing will strip parent attribute from the child page.

Unfortunately this is actually the same behavior as the classic editor. One could argue that you should be able to set page hierarchy regardless of publish status, but I think the reasoning behind it is to avoid confusion about visibility of a page.

Thank you for your tests @luminuu, @Soean, and @earnjam. In my tests, I found the same situation described by @earnjam so I'm am closing this issue for now, if any additional details exist and this problem is persisting feel free to reopen and I will look further.

I can still reproduce the bug in the current master with the steps described by @luminuu

Its important to add content to the page before you publish it.

I can't reproduce personally. I first thought it was related to the second meta box save (do you have meta boxes on your page), but even with meta boxes, I'm not able to reproduce with the exact steps. Could this be a conflict with another plugin?

No plugins active. I think it's something with the autosave function.

  1. Create a page, set a parent page and just save.
  2. Leave the editor and reopen the page. Change something and wait for Autosave.
  3. Click publish. The parent site is gone.

I was able to reproduce without even publishing the page. Yes, so just make some changes and wait for the autosave to trigger. After that you can see in the listing that the parent is not set anymore.

cc @aduth @adamsilverstein

I imagine it has something to do with this line, and a confusion on parent in the revision sense (attach revision to the original post) and parent the page parent.

https://github.com/WordPress/gutenberg/blob/c8b4679b901e7239afb0154a367bf7b9b024a535/packages/editor/src/store/effects/posts.js#L113

Also suspect:

https://github.com/WordPress/wordpress-develop/blob/abfbb344f100ee1332b633fd4bfee99fa2f43bb5/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L190-L193

Because we're passing parent (as in, the post to which the revision should be attached), I imagine it's treating this as a field to update on the post itself. This is the wrong behavior in that it will override the assigned parent field.

This may require one of two changes:

  • Stop passing parent unless the post is published
  • The REST API should disregard parent in calling wp_update_post for the draft & auto-draft case

My preference would be the second of these.

I imagine it has something to do with this line, and a confusion on parent in the revision sense (attach revision to the original post) and parent the page parent.

https://github.com/WordPress/gutenberg/blob/c8b4679b901e7239afb0154a367bf7b9b024a535/packages/editor/src/store/effects/posts.js#L113

Why do we even include this in the body of the payload? If the parent is already part of the fragment of the request URL, e.g. POST /wp/v2/pages/<parent>/autosaves.

I still think the REST API should be disregarding the value all the same, if it's intended that the only fields to be updateable on the post are title, content, and excerpt.

Proposed fix at #11513

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tofumatt picture tofumatt  路  86Comments

smp303 picture smp303  路  98Comments

jasmussen picture jasmussen  路  173Comments

azaozz picture azaozz  路  91Comments

melchoyce picture melchoyce  路  95Comments