RTC: Fix every update block refresh when a peer edits with in the code editor#78483
Conversation
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: +64 B (0%) Total Size: 8.04 MB 📦 View Changed
ℹ️ View Unchanged
|
|
Flaky tests detected in 17a8ea1. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/26300930204
|
|
In testing, I noticed that if you have simultaneous typing, the cursor in the code editor jumps to end. Below, user A is using the visual editor and (simulated) typing, and user B is trying to edit within the code editor. However, at each sync, the code editor cursor for user B jumps to the end of the code editor's text: cursor-jumping.movI'm looking into this issue as well. |
|
I'm going to address the code editor cursor-jumping behavior above in another PR. |
|
I opened up an issue for the cursor-resetting issue noted above in #78694. |
What?
Closes #76598.
When running with real-time collaboration, fixes embed blocks (YouTube, PDF, etc.) and all other blocks from refreshing on a collaborator's screen every time another user types in the code editor during a real-time editing session.
Before User A's embeds flash each time a sync update arrives:
code-editor-embed-refresh.mov
After User A's blocks stay stable during code editing:
embed-fix.mov
Why?
When a user is making changes in the code editor, it dispatches a new
contentstring with{ blocks: undefined }on every keystroke. In the CRDT sync layer, an empty blocks property caused the receiver to re-parse content from scratch, replacing the existing YDoc array of blocks and generating freshclientIds for every block. This caused every block to remount on every sync, which caused the embed iframe to reinitialize and re-load content, flashing.How?
Two changes in the CRDT layer:
applyPostChangesToCRDTDoc, when empty blocks arrive withcontent,mergeContentWithoutBlocks()parses the content and feeds it through the existingmergeCrdtBlocks()diff instead of wiping theY.Arrayand starting from scratch.mergeCrdtBlocks()update loop, a newcase 'clientId'skips the property entirely so the local Y.Doc clientId is never overwritten by an incoming freshly-parsed one. This solves the "reload on change" case for the individual block being modified in the code editor, avoiding a new client ID being synced on the newly parsed block and causing it to remount.Testing Instructions
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Used for: Investigating the bug, planning the fix, implementing the CRDT-layer changes, and writing unit tests.