Repository navigation
Core Data: Merge block metadata attribute structurally in RTC to prevent orphaned notes - #79956
adamsilverstein wants to merge 8 commits into
Conversation
The generic block `metadata` attribute is registered as a plain
`{ type: 'object' }` attribute with no query schema, so the CRDT merge
layer stored it as a plain value and replaced it wholesale on every
change. When two collaborators wrote metadata concurrently (e.g. both
attaching a note to the same block at the same moment), Yjs resolved the
concurrent map set last-writer-wins and one peer's note id was
discarded, orphaning that note with 'Original block deleted'.
Store metadata as a Y.Map and its noteId key as a Y.Array that is
materialized for every block, so concurrent note additions insert into
the same shared array and commute instead of racing on container
creation. Set-type keys are diffed with set semantics and their
containers are cleared but never deleted; other metadata keys merge
per-key. Empty containers are stripped whenever blocks are read out of
the document so editor state and serialized content are unchanged.
Fixes #74751
Holds all wp-sync requests on both collaborators' pages while each adds a note to the same block, then releases them so the concurrent updates merge. Verifies the block references both notes on both pages, both threads render for both users, and neither note is orphaned. Lives under http-only/ because pausing replication through request interception only works with the HTTP polling provider. Verified to fail (one note id discarded) against a build without the metadata merge fix and pass with it. See #74751
|
Size Change: +539 B (+0.01%) Total Size: 7.74 MB 📦 View Changed
|
|
Flaky tests detected in 040c1f3. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/28887425590
|
|
I think this is a more general issue with RTC and complex block attributes. This probably needs a general solution rather than a metadata-attribute-specific one. |
I'm not very familiar with this area and relied heavily on AI, but I tried it with #81046. |
…-notes-rtc # Conflicts: # packages/core-data/src/utils/test/crdt-blocks.jsdom.test.ts # packages/core-data/src/utils/test/crdt.jsdom.test.ts
Trunk upgraded wp-prettier to 3.9.6 and dropped dependency group comment blocks from import headers; reformat the branch's files so the lint job passes after the trunk merge. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CdtuWidg1XBK8cpYLNSWxF
🤖 PR meta 🤖🎉 PropsIf 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. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 📦 Bundle sizeSize Change: +505 B (+0.01%) Total Size: 8.61 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome 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. Page List converts to Navigation Links with entity bindings in
|
Trunk moved floating notes into a canvas margin (#83786), so the note form is no longer inside the Editor settings region unless the All notes sidebar is open. Open it on both pages, as the other collaboration notes tests do.
|
Closing in favor of |
Fixes #74751
What?
When two collaborators add a note to the same block at the same moment, one of the notes ends up orphaned and shows "Original block deleted" for its author, while the other collaborator cannot see it at all. This PR makes the block
metadataattribute merge structurally in the real-time collaboration layer so concurrent note additions both survive.Why?
#75147 made it possible for multiple note threads to co-exist on one block (
metadata.noteIdbecame an array), but the RTC layer still stored the wholemetadataattribute as a plain value in the CRDT document. The genericmetadataattribute is registered as{ type: 'object' }with no query schema (packages/block-editor/src/hooks/metadata.js), andmergeCrdtBlocksonly creates structured Yjs types forrich-text,array+query, andobject+query attributes. Everything else is replaced wholesale viaY.Map.set().Concurrent
set()calls on the same key are resolved last-writer-wins by Yjs, so when peer A wrote{ noteId: [ 101 ] }and peer B concurrently wrote{ noteId: [ 102 ] }, one write was discarded entirely and that note lost its block reference.As @Mamaduka noted on the issue, this is not specific to Notes: any feature using block
metadatafor storage hits the same race.How?
All changes are in
packages/core-data:metadataattribute is now stored as aY.Map, and itsnoteIdkey as aY.Array. Both containers are materialized for every block in the document (even when empty), so concurrent first writes from two peers insert into the same shared array - concurrent insertions commute in Yjs - instead of racing to create the container (container creation is itself last-writer-wins).noteIdis merged with set semantics (missing ids deleted, new ids appended); its container is cleared but never deleted, so a temporarily-empty incoming state can't destroy the shared array. Other metadata keys (name,bindings, ...) merge per-key instead of clobbering the whole object.deserializeBlockAttributes, the persisted-content comparison, and theareBlocksEqualdiff), so editor state, serialized post content, and dirty-state detection are unchanged.metadatafrom documents created before this change is upgraded to the structured form on the next merge.metadataattribute with a query schema keep the existing schema-driven merge behavior.The set-mergeable key list is a constant (
METADATA_SET_KEYS = [ 'noteId' ]) so other metadata-based features can opt in later.Testing Instructions
Automated:
The new e2e test holds all
wp-syncrequests on both collaborators' pages while each user adds a note to the same block, then releases them so the concurrent updates merge. It was verified to fail against a build without the fix (the block ends up with a singlenoteIdand one note is discarded) and to pass with it. It lives underhttp-only/because pausing replication via request interception only works with the HTTP polling provider.Manual: