-
Notifications
You must be signed in to change notification settings - Fork 4.8k
RTC: Fix Block Hooks auto-inserted blocks duplication on collaboration #76895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+72
−23
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,11 +76,36 @@ export interface YPostRecord extends YMapRecord { | |
|
|
||
| export const POST_META_KEY_FOR_CRDT_DOC_PERSISTENCE = '_crdt_document'; | ||
|
|
||
| // Post meta keys that should *not* be synced. | ||
| const disallowedPostMetaKeys = new Set< string >( [ | ||
| POST_META_KEY_FOR_CRDT_DOC_PERSISTENCE, | ||
| ] ); | ||
|
|
||
| // Post meta keys that are server-managed and must not be sent by the client | ||
| // during saves. Sending stale client values for these keys overwrites the | ||
| // server's calculations (e.g. update_ignored_hooked_blocks_postmeta). | ||
| const serverManagedPostMetaKeys = new Set< string >( [ | ||
| '_wp_ignored_hooked_blocks', | ||
| ] ); | ||
|
|
||
| /** | ||
| * Remove server-managed meta keys from a record's meta object in place. | ||
| * These keys are calculated by the server during save and must not be | ||
| * overwritten by possibly stale client values. | ||
| * | ||
| * @param {Object} record An entity record with an optional `meta` property. | ||
| */ | ||
| export function stripServerManagedMeta( | ||
| record: Record< string, unknown > | ||
| ): void { | ||
| const meta = record.meta; | ||
| if ( ! meta || typeof meta !== 'object' ) { | ||
| return; | ||
| } | ||
| serverManagedPostMetaKeys.forEach( ( metaKey ) => { | ||
| delete ( meta as Record< string, unknown > )[ metaKey ]; | ||
| } ); | ||
| } | ||
|
|
||
|
Comment on lines
+83
to
+108
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without knowing too much about RTC, this seems backwards -- the |
||
| /** | ||
| * Given a set of local changes to a generic entity record, apply those changes | ||
| * to the local Y.Doc. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shallow-cloning in the resolver and mutating via function call feels like the wrong fix.
At the very least, we can move this logic to
prePersistPostTypeinentities.js. There, the record is already cloned in order to amend it with additional edits. I can imagine something like aaddPersistedCrdtDocToPostRecordfunction that is exported fromcrdt.tsand called fromprePersistPostType.However, what nags is that the root cause of this issue is something different: We are calling
saveEntityRecordin thepersistCrdtDocrecord handler, which results in saving the entire record, not just fields that have changed.User-initiated saves, on the other hand, are conducted via
saveEditedEntityRecordwhich saves only the "dirty" fields. Therefore_wp_ignored_hooked_blockswould never be among them.Most likely, the best fix is to persist CRDT documents outside of post meta (i.e., in the sync data table) where it does not need to interfere with the save data.
Short of that, moving this logic to
entities.jsis probably better.