RTC: Fix "Edit as HTML" content reset during collaboration#77043
RTC: Fix "Edit as HTML" content reset during collaboration#77043alecgeatches merged 2 commits intotrunkfrom
Conversation
… collaborative editing
|
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: +6 B (0%) Total Size: 7.74 MB
ℹ️ View Unchanged
|
Mamaduka
left a comment
There was a problem hiding this comment.
The fix looks good. We should probably create a new issue and discuss soluton for #76980 (comment).
P.S. I've restarted failing e2e tests, not sure if it's flaky or related to this change. Worth checking if it fails again.
|
Flaky tests detected in 4440dc1. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/23957077413
|
@Mamaduka Thank you for the reviews! From some local explorations, I think we may have addressed most of the issues between |
* Precompute blockContent to prevent RESET_BLOCKS from interfering with collaborative editing * Memoize block content to avoid `getBlockContent()` every render
What?
Fixes the "Edit as HTML" block losing user input during real-time collaboration when another user makes any edit:
html-content-reset-on-edit.mov
Changes in HTML mode are immediately reset when another user makes change to the document
This is another block in the RTC
RESET_BLOCKSsaga (#76980, #76025), see this comment for a good explanation on this class of bugs: #76980 (comment).Why?
When two users are collaborating and one switches a block to "Edit as HTML" mode, every remote edit causes the HTML area to reset, discarding changes. This makes the HTML editing mode effectively unusable during collaboration.
The root cause is a
useEffectin theBlockHTMLcomponent based on theblockobject. During RTC sync,RESET_BLOCKSrebuilds the block tree with new objects, even for blocks whose content hasn't changed. SinceuseEffectuses reference, it fired on every sync and callssetHtml(getBlockContent(block)), overwriting in-progress changes.How?
The fix precomputes block content as a string outside of the effect.
useEffect()now depends on this string value rather than the block object reference. Since identical HTML strings are equal, the effect only fires when the block's serialized content genuinely changes. Peer edits to other blocks won't overwrite the text area, while edits to the same block still update it correctly:html-content-reset-fix.mov
Successfully typing in HTML mode during peer changes
Testing Instructions
This bug is difficult to test without real collaboration, because clicking out of the "Edit as HTML" box into another browser blur and commits content. The reproduction above and test steps below work best when tested on a live environment.
class="test"to the element). Do not blur or click away.trunk, this would reset the content of the edited HTML to the original state.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Used for: Discovery, root cause analysis, fix