Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft child pages: parent is removed when an autosave is performed #10753

Closed
luminuu opened this issue Oct 18, 2018 · 11 comments
Closed

Draft child pages: parent is removed when an autosave is performed #10753

luminuu opened this issue Oct 18, 2018 · 11 comments
Labels
REST API Interaction Related to REST API [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@luminuu
Copy link
Member

luminuu commented Oct 18, 2018

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
@Soean
Copy link
Member

Soean commented Oct 18, 2018

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

@Soean Soean added the [Type] Bug An existing feature does not function as intended label Oct 18, 2018
@Soean Soean added this to the WordPress 5.0 milestone Oct 18, 2018
@earnjam
Copy link
Contributor

earnjam commented Oct 23, 2018

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.

@jorgefilipecosta
Copy link
Member

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.

@Soean
Copy link
Member

Soean commented Nov 3, 2018

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.

@Soean Soean reopened this Nov 3, 2018
@youknowriad youknowriad self-assigned this Nov 5, 2018
@youknowriad
Copy link
Contributor

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?

@youknowriad youknowriad added the [Status] Needs More Info Follow-up required in order to be actionable. label Nov 5, 2018
@Soean
Copy link
Member

Soean commented Nov 5, 2018

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.

@youknowriad youknowriad changed the title Draft child pages: parent is removed when publishing Draft child pages: parent is removed when an autosave is performed Nov 5, 2018
@youknowriad
Copy link
Contributor

youknowriad commented Nov 5, 2018

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

@youknowriad youknowriad removed the [Status] Needs More Info Follow-up required in order to be actionable. label Nov 5, 2018
@aduth
Copy link
Member

aduth commented Nov 5, 2018

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.

@aduth
Copy link
Member

aduth commented Nov 5, 2018

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.

@aduth
Copy link
Member

aduth commented Nov 5, 2018

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.

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.

@aduth
Copy link
Member

aduth commented Nov 5, 2018

Proposed fix at #11513

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
REST API Interaction Related to REST API [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

7 participants