Skip to content

RTC: Prevent controlled block synchronization from intercepting undo - #80503

Merged
maxschmeling merged 7 commits into
trunkfrom
codex/rtc-undo-on-self-update
Jul 28, 2026
Merged

RTC: Prevent controlled block synchronization from intercepting undo#80503
maxschmeling merged 7 commits into
trunkfrom
codex/rtc-undo-on-self-update

Conversation

@maxschmeling

Copy link
Copy Markdown
Contributor

What?

This PR prevents entity-driven controlled block synchronization from adding derived changes to RTC undo history.

It also adds an end-to-end reproduction covering a post with a Navigation block where a delayed self-update previously intercepted a collaborator's first undo.

Follow-up to #78864.

Why?

RTC uses one global undo ordering across multiple Yjs documents. After a collaborator typed in the post body, the incoming round-trip update could cause the controlled Navigation block to emit a derived wp_navigation entity edit. That edit was tracked on a separate Yjs document and placed above the user's typing in the global undo stack.

As a result, pressing undo once popped an invisible Navigation update instead of removing the typed character. The feedback update could also clear redo.

How?

Controlled block setup, replacement, reset, and cleanup are already marked non-persistent because they reflect incoming entity state. This PR additionally marks those derived changes with history: 'ignore'.

useBlockSync already propagates that history mode as undoIgnore: true, so the derived Navigation update is excluded from Yjs undo history while direct user-authored Navigation edits remain tracked.

Testing Instructions

  1. Start the test environment if needed: npm run wp-env-test start.

  2. Run:

    RTC_WS_DELAY=50 npm run test:e2e:rtc-websocket -- test/e2e/specs/editor/collaboration/collaboration-undo-navigation-block.spec.ts
  3. Confirm the test passes and the delayed User B Navigation edit is logged with undoIgnore=true.

  4. Run the hook unit tests:

    npm run test:unit -- packages/block-editor/src/components/provider/test/use-block-sync.js

For a manual check, run RTC_WS_DELAY=50 npm run rtc:ws, open the same post in two administrator sessions, and include a Navigation block between paragraphs. Type one character in a paragraph as the second user, wait at least two seconds, and press undo once. The character should be removed and redo should remain available.

Testing Instructions for Keyboard

Follow the manual steps above and use the platform undo shortcut (Cmd+Z on macOS or Ctrl+Z elsewhere). The typed character should be removed with one shortcut press.

Screenshots or screencast

Not applicable; this changes undo-stack behavior without changing the UI.

Use of AI Tools

AI assistance: Yes
Tool: Codex
Used for: Investigating the RTC undo data flow, implementing the fix, running automated and manual verification, and drafting this description.

@maxschmeling maxschmeling added [Type] Bug An existing feature does not function as intended [Feature] History History, undo, redo, revisions, autosave. [Package] Block editor /packages/block-editor [Feature] Real-time Collaboration Phase 3 of the Gutenberg roadmap around real-time collaboration labels Jul 21, 2026
@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown

Size Change: +13 B (0%)

Total Size: 7.75 MB

📦 View Changed
Filename Size Change
build/scripts/block-editor/index.min.js 428 kB +13 B (0%)

compressed-size-action

@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown

Flaky tests detected in da96511.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/29944099202
📝 Reported issues:

@maxschmeling
maxschmeling marked this pull request as ready for review July 22, 2026 17:50
@maxschmeling
maxschmeling requested a review from ellatrix as a code owner July 22, 2026 17:50
@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: alecgeatches <alecgeatches@git.wordpress.org>
Co-authored-by: maxschmeling <maxschmeling@git.wordpress.org>
Co-authored-by: ingeniumed <ingeniumed@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@ingeniumed ingeniumed left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments around the test need to be tweaked other LGTM

Comment thread test/e2e/specs/editor/collaboration/collaboration-undo-navigation-block.spec.ts Outdated
Comment thread test/e2e/specs/editor/collaboration/collaboration-undo-navigation-block.spec.ts Outdated
@maxschmeling
maxschmeling merged commit 9ff41e2 into trunk Jul 28, 2026
43 checks passed
@maxschmeling
maxschmeling deleted the codex/rtc-undo-on-self-update branch July 28, 2026 18:18
@github-actions github-actions Bot added this to the Gutenberg 23.7 milestone Jul 28, 2026
@maxschmeling maxschmeling added the Backport to Gutenberg RC Pull request that needs to be backported to a Gutenberg release candidate (RC) label Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backport to Gutenberg RC Pull request that needs to be backported to a Gutenberg release candidate (RC) [Feature] History History, undo, redo, revisions, autosave. [Feature] Real-time Collaboration Phase 3 of the Gutenberg roadmap around real-time collaboration [Package] Block editor /packages/block-editor [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants