Make WordPress Core

Opened 3 weeks ago

Closed 13 days ago

#65008 closed defect (bug) (fixed)

Block Hooks / RTC: Auto-inserted blocks duplicated on page refresh or collaborator join

Reported by: bernhard-reiter's profile Bernhard Reiter Owned by: bernhard-reiter's profile Bernhard Reiter
Milestone: 7.0 Priority: normal
Severity: normal Version: trunk
Component: Editor Keywords: has-patch dev-reviewed
Focuses: Cc:

Description

As reported here by @ingeniumed, with some edits by myself

When real-time collaboration is activated, if a post contains blocks auto-inserted by the Block Hooks API, joining a real-time collaboration session (via page refresh or a second collaborator opening the post) causes the hooked blocks to be duplicated in the editor. The duplication compounds with each new session join, and each additional collaborator or refresh adds another copy of every hooked block.

Step-by-step reproduction instructions

  1. Enable real-time collaboration (in Settings > Writing).
  2. Create a new post and add a core/heading block and a core/paragraph block.
  3. Publish or save the post, then close it.
  4. Activate the Gutenberg Block Hooks plugin from `packages/e2e-test/plugins` (or any plugin that registers blocks via the Block Hooks API).
  5. Reopen the post. The Block Hooks API auto-inserts its blocks (in the after and last_child positions).
  6. Without saving, reload the post. Observe that the auto-inserted paragraph at the end of the post has been duplicated. Notice that every subsequent reload adds another copy.

Alternative to item 5: Open the same post in a second browser window or tab to simulate a second collaborator joining the RTC session.

Change History (7)

#1 @Bernhard Reiter
3 weeks ago

  • Owner set to Bernhard Reiter
  • Status changed from new to assigned

This ticket was mentioned in PR #11410 on WordPress/wordpress-develop by @Bernhard Reiter.


3 weeks ago
#2

  • Keywords has-patch added

_Proof of concept, needs polish._

Fixes https://github.com/WordPress/gutenberg/issues/76176.

See https://github.com/WordPress/gutenberg/pull/76895#issuecomment-4162625780 and https://github.com/WordPress/gutenberg/pull/76895#issuecomment-4163602210 for an explanation.

More details to follow

Trac ticket: https://core.trac.wordpress.org/ticket/65008

## Testing Instructions

_tl;dr:_ Verify that https://github.com/WordPress/gutenberg/issues/76176 is fixed.

## TODO

This needs more work, mostly in terms of performance: It adds another full traversal of a given post's block tree, which we should be able to avoid by more cleverly extracting information that's readily available from an earlier traversal, but it will require rethinking some interfaces.

I also need to double-check if it has any other unwanted side effects (unit test coverage should help with that).

## Use of AI Tools

None

#3 @jonsurrell
13 days ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 62219:

Block Hooks: Set ignored blocks meta in REST API response.

Set _wp_ignored_hooked_blocks post meta in the REST API response sent from post-like endpoints that support Block Hooks (see rest_block_hooks_post_types filter).

Previously, it was enough to set that post meta on write (i.e. save to DB). However, due to the way real-time collaboration syncs posts and reconciles them with content received from the server side, this information is now vital on the client side to ensure hooked blocks aren't duplicated.

Developed in https://github.com/WordPress/wordpress-develop/pull/11410.

Props bernhard-reiter, czarate, ingeniumed.
Fixes #65008.

#4 @Bernhard Reiter
13 days ago

  • Keywords dev-feedback added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening for the backport to 7.0.
(It meets the criteria: Fixes a bug that was introduced during the 7.0 cycle.)

@Bernhard Reiter commented on PR #11410:


13 days ago
#5

Re-opening to rebase on top of 7.0 branch, to run CI there.

#6 @jonsurrell
13 days ago

  • Keywords dev-reviewed added; dev-feedback removed

Approving [62219] for 7.0 backport. It's a 7.0 bugfix for RTC and satisfies the requirements.

#7 @jonsurrell
13 days ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 62220:

Block Hooks: Set ignored blocks meta in REST API response.

Set _wp_ignored_hooked_blocks post meta in the REST API response sent from post-like endpoints that support Block Hooks (see rest_block_hooks_post_types filter).

Previously, it was enough to set that post meta on write (i.e. save to DB). However, due to the way real-time collaboration syncs posts and reconciles them with content received from the server side, this information is now vital on the client side to ensure hooked blocks aren't duplicated.

Developed in https://github.com/WordPress/wordpress-develop/pull/11410.

Reviewed by jonsurrell.
Merges [62219] to the 7.0 branch.

Props bernhard-reiter, czarate, ingeniumed.
Fixes #65008.

Note: See TracTickets for help on using tickets.