Automattic / Co-Authors-Plus

Multiple bylines and Guest Authors for WordPress
https://wordpress.org/plugins/co-authors-plus/
GNU General Public License v2.0
290 stars 205 forks source link

fix subscribing triggering multiple saves #920

Closed leogermani closed 1 year ago

leogermani commented 1 year ago

Description

After the last review, several sites are experiencing issues when saving posts.

They describe that when they remove an author from the list and save, the original author is added back to the post.

I noticed that the subscribe callback is triggering multiple ajax requests to save the post. I fixed it by putting the subscribe call outside the component, and thus running it only once. This is how things were done before. It seems to solve the issue.

Context: In https://github.com/Automattic/Co-Authors-Plus/pull/870 the subscribe was removed and the changes were saved instantly. https://github.com/Automattic/Co-Authors-Plus/pull/914 reintroduced the subscribe behavior.

There are other issues though, that were not introduced by the latest changes, which this PR does not fix.

These 2 bugs are not new and should be addressed in other PRs

Deploy Notes

None

Steps to Test

On master

  1. Edit a post with multiple authors
  2. Remove an author from the list and Update the post
  3. Inspect the Network tab and notice there are at least two requests to coauthors/v1/authors/{$POST_ID}?new_authors={$AUTHORS_NICENAMES}&_locale=user

Apply this branch and do the same.

  1. Verify that every time you save the post only one request is made with the correct list of authors.
  2. Try to edit the authors in a way only one guest author is the author
  3. Try to edit the authors in a way only one WP user is the author