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

Editing a Pattern Duplicates Authors When Saving from Post Editor #69485

Open
3 of 6 tasks
NickGreen opened this issue Mar 7, 2025 · 4 comments
Open
3 of 6 tasks

Editing a Pattern Duplicates Authors When Saving from Post Editor #69485

NickGreen opened this issue Mar 7, 2025 · 4 comments
Labels
[Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Feature] Saving Related to saving functionality [Type] Bug An existing feature does not function as intended

Comments

@NickGreen
Copy link

Description

When editing a pattern from within a post editor, saving the pattern can result in duplicate author assignments. This appears to be caused by the block editor mixing context between the parent post and the pattern being edited.

This is with Co-Authors Plus active. Investigation has shown that the coauthors endpoint is being fed duplicate data, and that it is the block editor that is where the problem lies.

Investigation & Analysis

Through detailed logging of REST API requests and entity context, we discovered:

  1. When saving a pattern from within a post editor, two contexts are active:

    • The parent post (e.g., ID: 5)
    • The pattern being edited (e.g., ID: 8)
  2. The sequence of events shows the issue:

    a. Pattern save initiated
    b. Pattern content updated via REST API
    c. Parent post save triggered
    d. Author update REST request sent with duplicates:
       POST /coauthors/v1/authors/8
       parameters: { "new_authors": "authorA,authorA,authorB" }
    
  3. The logs show that the block editor is retrieving author data from both:

    • The current pattern context
    • The parent post context
      (and is also failing to deduplicate the combined author list before sending the update)

Suggested Solution

The block editor should maintain clear separation between pattern and post contexts when handling author assignments. Specifically:

  1. When saving a pattern, only use the pattern's context for author assignments
  2. Consider adding explicit context tracking for nested editor sessions (pattern editor within post editor)

This would prevent the duplicate author assignments while maintaining the expected co-author functionality for both patterns and posts.

Notes

  • We have also observed behavior where editing a synced pattern will assign that author to any posts in which that synced pattern is used. However, we can't duplicate with regularity, so we are leaving that particular situation out of this issue. But we are hopeful that it will also solve that problem.
  • A very similar issue was fixed here, and it appears that the same edit-post area of the code handles this behavior as well.

Step-by-step reproduction instructions

  1. Create a post logged in as Author A
  2. Create a synced pattern from within that post's editor and add it to the post's content
  3. Log into the site as Author B
  4. Edit the post, then edit the pattern from within that post
  5. Save the pattern
  6. Observe that the pattern now has duplicate author entries (e.g., "Author A, Author A, Author B")

Screenshots, screen recording, code snippet

Image

Environment info

  • WordPress Version: 6.7.2
  • Co-Authors Plus Version: 3.6.3
  • Gutenberg Version 20.4.0
  • Twenty Twenty-Five theme

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure
@NickGreen NickGreen added the [Type] Bug An existing feature does not function as intended label Mar 7, 2025
@Rishit30G
Copy link
Contributor

Thanks for sharing the issue,

I was able to reproduce the issue and can confirm that duplicate authors are displayed, sharing the screencast for the same:

Screen.Recording.2025-03-10.at.9.29.07.AM.mov

Active Plugins: Gutenberg, Co-Authors Plus, User Switching
Theme: Twenty Twenty Four
Gutenberg: 20.4.1-rc.1
WordPress: 6.7.2

@Mamaduka Mamaduka added Needs Testing Needs further testing to be confirmed. [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced labels Mar 10, 2025
@Mamaduka
Copy link
Member

@Rishit30G, can you confirm if the issue can be reproduced on WP 6.7 without the Gutenberg plugin active? Thanks!

@Rishit30G
Copy link
Contributor

Hi @Mamaduka,

On WordPress 6.7 and without Gutenberg Plugin the issue still persists

Screen.Recording.2025-03-10.at.1.35.45.PM.mov
Image

@Mamaduka
Copy link
Member

Thanks for the confirmation, @Rishit30G!

@Mamaduka Mamaduka added [Feature] Saving Related to saving functionality and removed Needs Testing Needs further testing to be confirmed. labels Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Feature] Saving Related to saving functionality [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

3 participants