Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Sync all meta by default
  • Loading branch information
chriszarate committed Oct 27, 2025
commit ab1c7f1516f1ae24a5e89454cac277278f0d51b0
63 changes: 0 additions & 63 deletions packages/core-data/src/utils/crdt-meta.ts

This file was deleted.

18 changes: 9 additions & 9 deletions packages/core-data/src/utils/crdt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { type Post } from '../entity-types/post';
import { type Type } from '../entity-types';
import { CRDT_DOC_META_PERSISTENCE_KEY, CRDT_RECORD_MAP_KEY } from '../sync';
import type { WPBlockSelection, WPSelection } from '../types';
import { shouldSyncMetaForPostType } from './crdt-meta';

export type PostChanges = Partial< Post > & {
blocks?: Block[];
Expand Down Expand Up @@ -54,6 +53,9 @@ const allowedPostProperties = new Set< string >( [
'title',
] );

// Post meta keys that should *not* be synced.
const disallowedPostMetaKeys = new Set< string >( [] );

/**
* Given a set of local changes to a generic entity record, apply those changes
* to the local Y.Doc.
Expand Down Expand Up @@ -96,13 +98,13 @@ export function defaultApplyChangesToCRDTDoc(
*
* @param {CRDTDoc} ydoc
* @param {PostChanges} changes
* @param {Type} postType
* @param {Type} _postType
* @return {void}
*/
export function applyPostChangesToCRDTDoc(
ydoc: CRDTDoc,
changes: PostChanges,
postType: Type
_postType: Type // eslint-disable-line @typescript-eslint/no-unused-vars
): void {
const ymap = ydoc.getMap( CRDT_RECORD_MAP_KEY );

Expand Down Expand Up @@ -164,9 +166,7 @@ export function applyPostChangesToCRDTDoc(
// should be synced.
Object.entries( newValue ?? {} ).forEach(
( [ metaKey, metaValue ] ) => {
if (
! shouldSyncMetaForPostType( metaKey, postType )
) {
if ( disallowedPostMetaKeys.has( metaKey ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an empty array, we can remove it as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I merge #72373, I will need to add the CRDT post meta to the set.

return;
}

Expand Down Expand Up @@ -234,13 +234,13 @@ export function defaultGetChangesFromCRDTDoc( crdtDoc: CRDTDoc ): ObjectData {
*
* @param {CRDTDoc} ydoc
* @param {Post} editedRecord
* @param {Type} postType
* @param {Type} _postType
* @return {Partial<PostChanges>} The changes that should be applied to the local record.
*/
export function getPostChangesFromCRDTDoc(
ydoc: CRDTDoc,
editedRecord: Post,
postType: Type
_postType: Type // eslint-disable-line @typescript-eslint/no-unused-vars
): PostChanges {
const ymap = ydoc.getMap( CRDT_RECORD_MAP_KEY );

Expand Down Expand Up @@ -311,7 +311,7 @@ export function getPostChangesFromCRDTDoc(
allowedMetaChanges = Object.fromEntries(
Object.entries( newValue ?? {} ).filter(
( [ metaKey ] ) =>
shouldSyncMetaForPostType( metaKey, postType )
! disallowedPostMetaKeys.has( metaKey )
)
);

Expand Down
25 changes: 2 additions & 23 deletions packages/core-data/src/utils/test/crdt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe( 'crdt', () => {
expect( blocks ).toBeInstanceOf( Y.Array );
} );

it( 'syncs non-hidden meta fields', () => {
it( 'syncs meta fields', () => {
const changes = {
meta: {
some_meta: 'new value',
Expand All @@ -169,24 +169,6 @@ describe( 'crdt', () => {
expect( metaMap.get( 'some_meta' ) ).toBe( 'new value' );
} );

it( 'does not sync hidden meta fields', () => {
const changes = {
meta: {
_private_meta: 'unsynced value',
some_meta: 'new value',
},
};

const metaMap = new Y.Map< unknown >();
metaMap.set( 'some_meta', 'old value' );
map.set( 'meta', metaMap );

applyPostChangesToCRDTDoc( doc, changes, mockPostType );

expect( metaMap.has( '_private_meta' ) ).toBe( false );
expect( metaMap.get( 'some_meta' ) ).toBe( 'new value' );
} );

it( 'initializes meta as Y.Map when not present', () => {
const changes = {
meta: {
Expand Down Expand Up @@ -299,15 +281,13 @@ describe( 'crdt', () => {
expect( changes ).toHaveProperty( 'blocks' );
} );

it( 'includes meta in changes, preserving any unsynced fields', () => {
it( 'includes meta in changes', () => {
map.set( 'meta', {
_private_meta: 'ignored value',
public_meta: 'new value',
} );

const editedRecord = {
meta: {
_private_meta: 'preserved value',
public_meta: 'old value',
},
} as unknown as Post;
Expand All @@ -319,7 +299,6 @@ describe( 'crdt', () => {
);

expect( changes.meta ).toEqual( {
_private_meta: 'preserved value', // preserved from edited record
public_meta: 'new value', // from CRDT
} );
} );
Expand Down