Skip to content

Commit 3e6657a

Browse files
committed
Remove IS_GUTENBERG_PLUGIN checks for collaborative editing
1 parent 1cb18ee commit 3e6657a

File tree

7 files changed

+227
-271
lines changed

7 files changed

+227
-271
lines changed

packages/core-data/src/actions.js

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,11 @@ export const deleteEntityRecord =
340340

341341
await dispatch( removeItems( kind, name, recordId, true ) );
342342

343-
if ( globalThis.IS_GUTENBERG_PLUGIN ) {
344-
if ( entityConfig.syncConfig ) {
345-
const objectType = `${ kind }/${ name }`;
346-
const objectId = recordId;
343+
if ( entityConfig.syncConfig ) {
344+
const objectType = `${ kind }/${ name }`;
345+
const objectId = recordId;
347346

348-
getSyncManager()?.unload( objectType, objectId );
349-
}
347+
getSyncManager()?.unload( objectType, objectId );
350348
}
351349
} catch ( _error ) {
352350
hasError = true;
@@ -427,35 +425,33 @@ export const editEntityRecord =
427425
return acc;
428426
}, {} ),
429427
};
430-
if ( globalThis.IS_GUTENBERG_PLUGIN ) {
431-
if ( entityConfig.syncConfig ) {
432-
const objectType = `${ kind }/${ name }`;
433-
const objectId = recordId;
434-
435-
// Determine whether this edit should create a new undo level.
436-
//
437-
// In Gutenberg, block changes flow through two callbacks:
438-
// - `onInput`: For transient/in-progress changes (e.g., typing each
439-
// character). These use `isCached: true` and get merged into
440-
// the current undo item.
441-
// - `onChange`: For persistent/completed changes (e.g., formatting
442-
// transforms, block insertions). These use `isCached: false` and
443-
// should create a new undo level.
444-
//
445-
// Additionally, `undoIgnore: true` means the change should not
446-
// affect the undo history at all (e.g., selection-only changes).
447-
const isNewUndoLevel = options.undoIgnore
448-
? false
449-
: ! options.isCached;
450-
451-
getSyncManager()?.update(
452-
objectType,
453-
objectId,
454-
editsWithMerges,
455-
LOCAL_EDITOR_ORIGIN,
456-
{ isNewUndoLevel }
457-
);
458-
}
428+
if ( entityConfig.syncConfig ) {
429+
const objectType = `${ kind }/${ name }`;
430+
const objectId = recordId;
431+
432+
// Determine whether this edit should create a new undo level.
433+
//
434+
// In Gutenberg, block changes flow through two callbacks:
435+
// - `onInput`: For transient/in-progress changes (e.g., typing each
436+
// character). These use `isCached: true` and get merged into
437+
// the current undo item.
438+
// - `onChange`: For persistent/completed changes (e.g., formatting
439+
// transforms, block insertions). These use `isCached: false` and
440+
// should create a new undo level.
441+
//
442+
// Additionally, `undoIgnore: true` means the change should not
443+
// affect the undo history at all (e.g., selection-only changes).
444+
const isNewUndoLevel = options.undoIgnore
445+
? false
446+
: ! options.isCached;
447+
448+
getSyncManager()?.update(
449+
objectType,
450+
objectId,
451+
editsWithMerges,
452+
LOCAL_EDITOR_ORIGIN,
453+
{ isNewUndoLevel }
454+
);
459455
}
460456
if ( ! options.undoIgnore ) {
461457
select.getUndoManager().addRecord(
@@ -796,16 +792,14 @@ export const saveEntityRecord =
796792
true,
797793
edits
798794
);
799-
if ( globalThis.IS_GUTENBERG_PLUGIN ) {
800-
if ( entityConfig.syncConfig ) {
801-
getSyncManager()?.update(
802-
`${ kind }/${ name }`,
803-
recordId,
804-
updatedRecord,
805-
LOCAL_EDITOR_ORIGIN,
806-
{ isSave: true }
807-
);
808-
}
795+
if ( entityConfig.syncConfig ) {
796+
getSyncManager()?.update(
797+
`${ kind }/${ name }`,
798+
recordId,
799+
updatedRecord,
800+
LOCAL_EDITOR_ORIGIN,
801+
{ isSave: true }
802+
);
809803
}
810804
}
811805
} catch ( _error ) {

packages/core-data/src/entities.js

Lines changed: 54 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,8 @@ export const rootEntitiesConfig = [
229229
].map( ( entity ) => {
230230
const syncEnabledRootEntities = new Set( [ 'comment' ] );
231231

232-
if ( globalThis.IS_GUTENBERG_PLUGIN ) {
233-
if ( syncEnabledRootEntities.has( entity.name ) ) {
234-
entity.syncConfig = defaultSyncConfig;
235-
}
232+
if ( syncEnabledRootEntities.has( entity.name ) ) {
233+
entity.syncConfig = defaultSyncConfig;
236234
}
237235
return entity;
238236
} );
@@ -295,16 +293,14 @@ export const prePersistPostType = (
295293
}
296294

297295
// Add meta for persisted CRDT document.
298-
if ( globalThis.IS_GUTENBERG_PLUGIN ) {
299-
if ( persistedRecord ) {
300-
const objectType = `postType/${ name }`;
301-
const objectId = persistedRecord.id;
302-
const meta = getSyncManager()?.createMeta( objectType, objectId );
303-
newEdits.meta = {
304-
...edits.meta,
305-
...meta,
306-
};
307-
}
296+
if ( persistedRecord ) {
297+
const objectType = `postType/${ name }`;
298+
const objectId = persistedRecord.id;
299+
const meta = getSyncManager()?.createMeta( objectType, objectId );
300+
newEdits.meta = {
301+
...edits.meta,
302+
...meta,
303+
};
308304
}
309305

310306
return newEdits;
@@ -359,60 +355,54 @@ async function loadPostTypeEntities() {
359355
: DEFAULT_ENTITY_KEY,
360356
};
361357

362-
if ( globalThis.IS_GUTENBERG_PLUGIN ) {
358+
/**
359+
* @type {import('@wordpress/sync').SyncConfig}
360+
*/
361+
entity.syncConfig = {
363362
/**
364-
* @type {import('@wordpress/sync').SyncConfig}
363+
* Apply changes from the local editor to the local CRDT document so
364+
* that those changes can be synced to other peers (via the provider).
365+
*
366+
* @param {import('@wordpress/sync').CRDTDoc} crdtDoc
367+
* @param {Partial< import('@wordpress/sync').ObjectData >} changes
368+
* @return {void}
365369
*/
366-
entity.syncConfig = {
367-
/**
368-
* Apply changes from the local editor to the local CRDT document so
369-
* that those changes can be synced to other peers (via the provider).
370-
*
371-
* @param {import('@wordpress/sync').CRDTDoc} crdtDoc
372-
* @param {Partial< import('@wordpress/sync').ObjectData >} changes
373-
* @return {void}
374-
*/
375-
applyChangesToCRDTDoc: ( crdtDoc, changes ) =>
376-
applyPostChangesToCRDTDoc( crdtDoc, changes, postType ),
370+
applyChangesToCRDTDoc: ( crdtDoc, changes ) =>
371+
applyPostChangesToCRDTDoc( crdtDoc, changes, postType ),
377372

378-
/**
379-
* Create the awareness instance for the entity's CRDT document.
380-
*
381-
* @param {import('@wordpress/sync').CRDTDoc} ydoc
382-
* @param {import('@wordpress/sync').ObjectID} objectId
383-
* @return {import('@wordpress/sync').Awareness} Awareness instance
384-
*/
385-
createAwareness: ( ydoc, objectId ) => {
386-
const kind = 'postType';
387-
const id = parseInt( objectId, 10 );
388-
return new PostEditorAwareness( ydoc, kind, name, id );
389-
},
373+
/**
374+
* Create the awareness instance for the entity's CRDT document.
375+
*
376+
* @param {import('@wordpress/sync').CRDTDoc} ydoc
377+
* @param {import('@wordpress/sync').ObjectID} objectId
378+
* @return {import('@wordpress/sync').Awareness} Awareness instance
379+
*/
380+
createAwareness: ( ydoc, objectId ) => {
381+
const kind = 'postType';
382+
const id = parseInt( objectId, 10 );
383+
return new PostEditorAwareness( ydoc, kind, name, id );
384+
},
390385

391-
/**
392-
* Extract changes from a CRDT document that can be used to update the
393-
* local editor state.
394-
*
395-
* @param {import('@wordpress/sync').CRDTDoc} crdtDoc
396-
* @param {import('@wordpress/sync').ObjectData} editedRecord
397-
* @return {Partial< import('@wordpress/sync').ObjectData >} Changes to record
398-
*/
399-
getChangesFromCRDTDoc: ( crdtDoc, editedRecord ) =>
400-
getPostChangesFromCRDTDoc(
401-
crdtDoc,
402-
editedRecord,
403-
postType
404-
),
386+
/**
387+
* Extract changes from a CRDT document that can be used to update the
388+
* local editor state.
389+
*
390+
* @param {import('@wordpress/sync').CRDTDoc} crdtDoc
391+
* @param {import('@wordpress/sync').ObjectData} editedRecord
392+
* @return {Partial< import('@wordpress/sync').ObjectData >} Changes to record
393+
*/
394+
getChangesFromCRDTDoc: ( crdtDoc, editedRecord ) =>
395+
getPostChangesFromCRDTDoc( crdtDoc, editedRecord, postType ),
405396

406-
/**
407-
* Sync features supported by the entity.
408-
*
409-
* @type {Record< string, boolean >}
410-
*/
411-
supports: {
412-
crdtPersistence: true,
413-
},
414-
};
415-
}
397+
/**
398+
* Sync features supported by the entity.
399+
*
400+
* @type {Record< string, boolean >}
401+
*/
402+
supports: {
403+
crdtPersistence: true,
404+
},
405+
};
416406

417407
return entity;
418408
} );
@@ -439,9 +429,7 @@ async function loadTaxonomyEntities() {
439429
supportsPagination: true,
440430
};
441431

442-
if ( globalThis.IS_GUTENBERG_PLUGIN ) {
443-
entity.syncConfig = defaultSyncConfig;
444-
}
432+
entity.syncConfig = defaultSyncConfig;
445433

446434
return entity;
447435
} );

packages/core-data/src/private-selectors.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,8 @@ type EntityRecordKey = string | number;
4040
* @return The undo manager.
4141
*/
4242
export function getUndoManager( state: State ) {
43-
if ( globalThis.IS_GUTENBERG_PLUGIN ) {
44-
// undoManager is undefined until the first sync-enabled entity is loaded.
45-
return getSyncManager()?.undoManager ?? state.undoManager;
46-
}
47-
48-
return state.undoManager;
43+
// undoManager is undefined until the first sync-enabled entity is loaded.
44+
return getSyncManager()?.undoManager ?? state.undoManager;
4945
}
5046

5147
/**

0 commit comments

Comments
 (0)