Skip to content

Commit 6814b70

Browse files
committed
Sync all meta by default
1 parent b967e77 commit 6814b70

File tree

3 files changed

+11
-95
lines changed

3 files changed

+11
-95
lines changed

packages/core-data/src/utils/crdt-meta.ts

Lines changed: 0 additions & 63 deletions
This file was deleted.

packages/core-data/src/utils/crdt.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { type Post } from '../entity-types/post';
2121
import { type Type } from '../entity-types';
2222
import { CRDT_RECORD_MAP_KEY } from '../sync';
2323
import type { WPBlockSelection, WPSelection } from '../types';
24-
import { shouldSyncMetaForPostType } from './crdt-meta';
2524

2625
export type PostChanges = Partial< Post > & {
2726
blocks?: Block[];
@@ -52,6 +51,9 @@ const allowedPostProperties = new Set< string >( [
5251
'title',
5352
] );
5453

54+
// Post meta keys that should *not* be synced.
55+
const disallowedPostMetaKeys = new Set< string >( [] );
56+
5557
/**
5658
* Given a set of local changes to a generic entity record, apply those changes
5759
* to the local Y.Doc.
@@ -94,13 +96,13 @@ export function defaultApplyChangesToCRDTDoc(
9496
*
9597
* @param {CRDTDoc} ydoc
9698
* @param {PostChanges} changes
97-
* @param {Type} postType
99+
* @param {Type} _postType
98100
* @return {void}
99101
*/
100102
export function applyPostChangesToCRDTDoc(
101103
ydoc: CRDTDoc,
102104
changes: PostChanges,
103-
postType: Type
105+
_postType: Type // eslint-disable-line @typescript-eslint/no-unused-vars
104106
): void {
105107
const ymap = ydoc.getMap( CRDT_RECORD_MAP_KEY );
106108

@@ -162,9 +164,7 @@ export function applyPostChangesToCRDTDoc(
162164
// should be synced.
163165
Object.entries( newValue ?? {} ).forEach(
164166
( [ metaKey, metaValue ] ) => {
165-
if (
166-
! shouldSyncMetaForPostType( metaKey, postType )
167-
) {
167+
if ( disallowedPostMetaKeys.has( metaKey ) ) {
168168
return;
169169
}
170170

@@ -232,13 +232,13 @@ export function defaultGetChangesFromCRDTDoc( crdtDoc: CRDTDoc ): ObjectData {
232232
*
233233
* @param {CRDTDoc} ydoc
234234
* @param {Post} editedRecord
235-
* @param {Type} postType
235+
* @param {Type} _postType
236236
* @return {Partial<PostChanges>} The changes that should be applied to the local record.
237237
*/
238238
export function getPostChangesFromCRDTDoc(
239239
ydoc: CRDTDoc,
240240
editedRecord: Post,
241-
postType: Type
241+
_postType: Type // eslint-disable-line @typescript-eslint/no-unused-vars
242242
): PostChanges {
243243
const ymap = ydoc.getMap( CRDT_RECORD_MAP_KEY );
244244

@@ -280,7 +280,7 @@ export function getPostChangesFromCRDTDoc(
280280
allowedMetaChanges = Object.fromEntries(
281281
Object.entries( newValue ?? {} ).filter(
282282
( [ metaKey ] ) =>
283-
shouldSyncMetaForPostType( metaKey, postType )
283+
! disallowedPostMetaKeys.has( metaKey )
284284
)
285285
);
286286

packages/core-data/src/utils/test/crdt.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ describe( 'crdt', () => {
153153
expect( blocks ).toBeInstanceOf( Y.Array );
154154
} );
155155

156-
it( 'syncs non-hidden meta fields', () => {
156+
it( 'syncs meta fields', () => {
157157
const changes = {
158158
meta: {
159159
some_meta: 'new value',
@@ -169,24 +169,6 @@ describe( 'crdt', () => {
169169
expect( metaMap.get( 'some_meta' ) ).toBe( 'new value' );
170170
} );
171171

172-
it( 'does not sync hidden meta fields', () => {
173-
const changes = {
174-
meta: {
175-
_private_meta: 'unsynced value',
176-
some_meta: 'new value',
177-
},
178-
};
179-
180-
const metaMap = new Y.Map< unknown >();
181-
metaMap.set( 'some_meta', 'old value' );
182-
map.set( 'meta', metaMap );
183-
184-
applyPostChangesToCRDTDoc( doc, changes, mockPostType );
185-
186-
expect( metaMap.has( '_private_meta' ) ).toBe( false );
187-
expect( metaMap.get( 'some_meta' ) ).toBe( 'new value' );
188-
} );
189-
190172
it( 'initializes meta as Y.Map when not present', () => {
191173
const changes = {
192174
meta: {
@@ -299,15 +281,13 @@ describe( 'crdt', () => {
299281
expect( changes ).toHaveProperty( 'blocks' );
300282
} );
301283

302-
it( 'includes meta in changes, preserving any unsynced fields', () => {
284+
it( 'includes meta in changes', () => {
303285
map.set( 'meta', {
304-
_private_meta: 'ignored value',
305286
public_meta: 'new value',
306287
} );
307288

308289
const editedRecord = {
309290
meta: {
310-
_private_meta: 'preserved value',
311291
public_meta: 'old value',
312292
},
313293
} as unknown as Post;
@@ -319,7 +299,6 @@ describe( 'crdt', () => {
319299
);
320300

321301
expect( changes.meta ).toEqual( {
322-
_private_meta: 'preserved value', // preserved from edited record
323302
public_meta: 'new value', // from CRDT
324303
} );
325304
} );

0 commit comments

Comments
 (0)