@wordpress/core-data 7.33.0 → 7.33.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,11 +4,18 @@ import {
4
4
  LOCAL_SYNC_MANAGER_ORIGIN,
5
5
  createSyncManager
6
6
  } from "@wordpress/sync";
7
- const syncManager = createSyncManager();
7
+ let syncManager;
8
+ function getSyncManager() {
9
+ if (syncManager) {
10
+ return syncManager;
11
+ }
12
+ syncManager = createSyncManager();
13
+ return syncManager;
14
+ }
8
15
  export {
9
16
  CRDT_RECORD_MAP_KEY,
10
17
  LOCAL_EDITOR_ORIGIN,
11
18
  LOCAL_SYNC_MANAGER_ORIGIN,
12
- syncManager
19
+ getSyncManager
13
20
  };
14
21
  //# sourceMappingURL=sync.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/sync.ts"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tCRDT_RECORD_MAP_KEY,\n\tLOCAL_EDITOR_ORIGIN,\n\tLOCAL_SYNC_MANAGER_ORIGIN,\n\tcreateSyncManager,\n} from '@wordpress/sync';\n\nexport { CRDT_RECORD_MAP_KEY, LOCAL_EDITOR_ORIGIN, LOCAL_SYNC_MANAGER_ORIGIN };\nexport const syncManager = createSyncManager();\n"],
5
- "mappings": "AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAGA,MAAM,cAAc,kBAAkB;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tCRDT_RECORD_MAP_KEY,\n\tLOCAL_EDITOR_ORIGIN,\n\tLOCAL_SYNC_MANAGER_ORIGIN,\n\ttype SyncManager,\n\tcreateSyncManager,\n} from '@wordpress/sync';\n\nexport { CRDT_RECORD_MAP_KEY, LOCAL_EDITOR_ORIGIN, LOCAL_SYNC_MANAGER_ORIGIN };\n\nlet syncManager: SyncManager;\n\nexport function getSyncManager(): SyncManager | undefined {\n\tif ( syncManager ) {\n\t\treturn syncManager;\n\t}\n\n\tsyncManager = createSyncManager();\n\n\treturn syncManager;\n}\n"],
5
+ "mappings": "AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,OACM;AAIP,IAAI;AAEG,SAAS,iBAA0C;AACzD,MAAK,aAAc;AAClB,WAAO;AAAA,EACR;AAEA,gBAAc,kBAAkB;AAEhC,SAAO;AACR;",
6
6
  "names": []
7
7
  }
@@ -2,6 +2,7 @@ export const DEFAULT_ENTITY_KEY: "id";
2
2
  export const rootEntitiesConfig: ({
3
3
  label: import("@wordpress/i18n").TranslatableText<"Base">;
4
4
  kind: string;
5
+ key: boolean;
5
6
  name: string;
6
7
  baseURL: string;
7
8
  baseURLParams: {
@@ -9,7 +10,6 @@ export const rootEntitiesConfig: ({
9
10
  context?: undefined;
10
11
  };
11
12
  plural: string;
12
- key?: undefined;
13
13
  rawAttributes?: undefined;
14
14
  supportsPagination?: undefined;
15
15
  transientEdits?: undefined;
@@ -259,6 +259,19 @@ export const rootEntitiesConfig: ({
259
259
  transientEdits?: undefined;
260
260
  getTitle?: undefined;
261
261
  getRevisionsUrl?: undefined;
262
+ } | {
263
+ label: import("@wordpress/i18n").TranslatableText<"Registered Templates">;
264
+ name: string;
265
+ kind: string;
266
+ baseURL: string;
267
+ key: string;
268
+ baseURLParams?: undefined;
269
+ plural?: undefined;
270
+ rawAttributes?: undefined;
271
+ supportsPagination?: undefined;
272
+ transientEdits?: undefined;
273
+ getTitle?: undefined;
274
+ getRevisionsUrl?: undefined;
262
275
  })[];
263
276
  export namespace deprecatedEntities {
264
277
  namespace root {
@@ -1 +1 @@
1
- {"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../src/entities.js"],"names":[],"mappings":"AAsBA,iCAAkC,IAAI,CAAC;AAYvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA0KE;;;;;;;;;;;;AAcF;;;;;;;;;;KASE;AASK,0EAqBN;AAiKM,oCANI,MAAM,QACN,MAAM,WACN,MAAM,GAEL,MAAM,CAMjB;AAnKD;;;;GAIG;AACH,sDA2EC;AAyBD;;;;GAIG;AACH,gDA6BC"}
1
+ {"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../src/entities.js"],"names":[],"mappings":"AAsBA,iCAAkC,IAAI,CAAC;AAYvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAkLE;;;;;;;;;;;;AAcF;;;;;;;;;;KASE;AASK,0EAqBN;AAmLM,oCANI,MAAM,QACN,MAAM,WACN,MAAM,GAEL,MAAM,CAMjB;AArLD;;;;GAIG;AACH,sDAoFC;AAyBD;;;;GAIG;AACH,gDAsCC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AA6HA;;;;GAIG;AACH;;;;;;;;;;;;;;;;;;;;;;4CAW07pB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAX93pB;;;;;;;2BAzHxC,aAAa"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AA6HA;;;;GAIG;AACH;;;;;;;;;;;;;;;;;;;;;;4CAWslqB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAX1hqB;;;;;;;2BAzHxC,aAAa"}
@@ -1 +1 @@
1
- {"version":3,"file":"private-selectors.d.ts","sourceRoot":"","sources":["../src/private-selectors.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,EAAyC,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAKhF,KAAK,eAAe,GAAG,MAAM,GAAG,MAAM,CAAC;AAEvC;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAE,KAAK,EAAE,KAAK,iDAE3C;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACtC,KAAK,EAAE,KAAK,GACV,eAAe,GAAG,SAAS,CAE7B;AAED,eAA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IGIN } from '@wordpress/sync';
4
+ import { CRDT_RECORD_MAP_KEY, LOCAL_EDITOR_ORIGIN, LOCAL_SYNC_MANAGER_ORIGIN, type SyncManager } from '@wordpress/sync';
5
5
  export { CRDT_RECORD_MAP_KEY, LOCAL_EDITOR_ORIGIN, LOCAL_SYNC_MANAGER_ORIGIN };
6
- export declare const syncManager: import("@wordpress/sync").SyncManager;
6
+ export declare function getSyncManager(): SyncManager | undefined;
7
7
  //# sourceMappingURL=sync.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACN,mBAAmB,EACnB,mBAAmB,EACnB,yBAAyB,EAEzB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,CAAC;AAC/E,eAAO,MAAM,WAAW,uCAAsB,CAAC"}
1
+ {"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACN,mBAAmB,EACnB,mBAAmB,EACnB,yBAAyB,EACzB,KAAK,WAAW,EAEhB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,CAAC;AAI/E,wBAAgB,cAAc,IAAI,WAAW,GAAG,SAAS,CAQxD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/core-data",
3
- "version": "7.33.0",
3
+ "version": "7.33.1",
4
4
  "description": "Access to and manipulation of core WordPress entities.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -40,22 +40,22 @@
40
40
  "{src,build,build-module}/index.js"
41
41
  ],
42
42
  "dependencies": {
43
- "@wordpress/api-fetch": "^7.33.0",
44
- "@wordpress/block-editor": "^15.6.0",
45
- "@wordpress/blocks": "^15.6.0",
46
- "@wordpress/compose": "^7.33.0",
47
- "@wordpress/data": "^10.33.0",
48
- "@wordpress/deprecated": "^4.33.0",
49
- "@wordpress/element": "^6.33.0",
50
- "@wordpress/html-entities": "^4.33.0",
51
- "@wordpress/i18n": "^6.6.0",
52
- "@wordpress/is-shallow-equal": "^5.33.0",
53
- "@wordpress/private-apis": "^1.33.0",
54
- "@wordpress/rich-text": "^7.33.0",
55
- "@wordpress/sync": "^1.33.0",
56
- "@wordpress/undo-manager": "^1.33.0",
57
- "@wordpress/url": "^4.33.0",
58
- "@wordpress/warning": "^3.33.0",
43
+ "@wordpress/api-fetch": "^7.33.1",
44
+ "@wordpress/block-editor": "^15.6.1",
45
+ "@wordpress/blocks": "^15.6.1",
46
+ "@wordpress/compose": "^7.33.1",
47
+ "@wordpress/data": "^10.33.1",
48
+ "@wordpress/deprecated": "^4.33.1",
49
+ "@wordpress/element": "^6.33.1",
50
+ "@wordpress/html-entities": "^4.33.1",
51
+ "@wordpress/i18n": "^6.6.1",
52
+ "@wordpress/is-shallow-equal": "^5.33.1",
53
+ "@wordpress/private-apis": "^1.33.1",
54
+ "@wordpress/rich-text": "^7.33.1",
55
+ "@wordpress/sync": "^1.33.1",
56
+ "@wordpress/undo-manager": "^1.33.1",
57
+ "@wordpress/url": "^4.33.1",
58
+ "@wordpress/warning": "^3.33.1",
59
59
  "change-case": "^4.1.2",
60
60
  "equivalent-key-map": "^0.2.2",
61
61
  "fast-deep-equal": "^3.1.3",
@@ -69,5 +69,5 @@
69
69
  "publishConfig": {
70
70
  "access": "public"
71
71
  },
72
- "gitHead": "2bbe0d34ab65458468758c48826296d7a753428b"
72
+ "gitHead": "5f84bafdec1bed05247c1080c12f6a237951b862"
73
73
  }
package/src/actions.js CHANGED
@@ -19,7 +19,7 @@ import { receiveItems, removeItems, receiveQueriedItems } from './queried-data';
19
19
  import { DEFAULT_ENTITY_KEY } from './entities';
20
20
  import { createBatch } from './batch';
21
21
  import { STORE_NAME } from './name';
22
- import { LOCAL_EDITOR_ORIGIN, syncManager } from './sync';
22
+ import { LOCAL_EDITOR_ORIGIN, getSyncManager } from './sync';
23
23
  import logEntityDeprecation from './utils/log-entity-deprecation';
24
24
 
25
25
  /**
@@ -415,7 +415,7 @@ export const editEntityRecord =
415
415
  const objectType = `${ kind }/${ name }`;
416
416
  const objectId = recordId;
417
417
 
418
- syncManager.update(
418
+ getSyncManager()?.update(
419
419
  objectType,
420
420
  objectId,
421
421
  edit.edits,
@@ -525,8 +525,9 @@ export const saveEntityRecord =
525
525
  if ( ! entityConfig ) {
526
526
  return;
527
527
  }
528
- const entityIdKey = entityConfig.key || DEFAULT_ENTITY_KEY;
528
+ const entityIdKey = entityConfig.key ?? DEFAULT_ENTITY_KEY;
529
529
  const recordId = record[ entityIdKey ];
530
+ const isNewRecord = !! entityIdKey && ! recordId;
530
531
 
531
532
  const lock = await dispatch.__unstableAcquireStoreLock(
532
533
  STORE_NAME,
@@ -580,11 +581,10 @@ export const saveEntityRecord =
580
581
  }
581
582
  try {
582
583
  const path = `${ baseURL }${ recordId ? '/' + recordId : '' }`;
583
- const persistedRecord = select.getRawEntityRecord(
584
- kind,
585
- name,
586
- recordId
587
- );
584
+ // Skip the raw values check when creating a new record; they don't exist yet.
585
+ const persistedRecord = ! isNewRecord
586
+ ? select.getRawEntityRecord( kind, name, recordId )
587
+ : {};
588
588
 
589
589
  if ( isAutosave ) {
590
590
  // Most of this autosave logic is very specific to posts.
package/src/entities.js CHANGED
@@ -36,6 +36,7 @@ export const rootEntitiesConfig = [
36
36
  {
37
37
  label: __( 'Base' ),
38
38
  kind: 'root',
39
+ key: false,
39
40
  name: '__unstableBase',
40
41
  baseURL: '/',
41
42
  baseURLParams: {
@@ -202,6 +203,13 @@ export const rootEntitiesConfig = [
202
203
  plural: 'statuses',
203
204
  key: 'slug',
204
205
  },
206
+ {
207
+ label: __( 'Registered Templates' ),
208
+ name: 'registeredTemplate',
209
+ kind: 'root',
210
+ baseURL: '/wp/v2/registered-templates',
211
+ key: 'id',
212
+ },
205
213
  ];
206
214
 
207
215
  export const deprecatedEntities = {
@@ -272,41 +280,7 @@ async function loadPostTypeEntities() {
272
280
  );
273
281
  const namespace = postType?.rest_namespace ?? 'wp/v2';
274
282
 
275
- /**
276
- * @type {import('@wordpress/sync').SyncConfig}
277
- */
278
- const syncConfig = {
279
- /**
280
- * Apply changes from the local editor to the local CRDT document so
281
- * that those changes can be synced to other peers (via the provider).
282
- *
283
- * @param {import('@wordpress/sync').CRDTDoc} crdtDoc
284
- * @param {Partial< import('@wordpress/sync').ObjectData >} changes
285
- * @return {void}
286
- */
287
- applyChangesToCRDTDoc: ( crdtDoc, changes ) =>
288
- applyPostChangesToCRDTDoc( crdtDoc, changes, postType ),
289
-
290
- /**
291
- * Extract changes from a CRDT document that can be used to update the
292
- * local editor state.
293
- *
294
- * @param {import('@wordpress/sync').CRDTDoc} crdtDoc
295
- * @param {import('@wordpress/sync').ObjectData} editedRecord
296
- * @return {Partial< import('@wordpress/sync').ObjectData >} Changes to record
297
- */
298
- getChangesFromCRDTDoc: ( crdtDoc, editedRecord ) =>
299
- getPostChangesFromCRDTDoc( crdtDoc, editedRecord, postType ),
300
-
301
- /**
302
- * Sync features supported by the entity.
303
- *
304
- * @type {Record< string, boolean >}
305
- */
306
- supports: {},
307
- };
308
-
309
- return {
283
+ const entity = {
310
284
  kind: 'postType',
311
285
  baseURL: `/${ namespace }/${ postType.rest_base }`,
312
286
  baseURLParams: { context: 'edit' },
@@ -326,7 +300,6 @@ async function loadPostTypeEntities() {
326
300
  : String( record.id ) ),
327
301
  __unstablePrePersist: isTemplate ? undefined : prePersistPostType,
328
302
  __unstable_rest_base: postType.rest_base,
329
- syncConfig,
330
303
  supportsPagination: true,
331
304
  getRevisionsUrl: ( parentId, revisionId ) =>
332
305
  `/${ namespace }/${
@@ -336,6 +309,50 @@ async function loadPostTypeEntities() {
336
309
  }`,
337
310
  revisionKey: DEFAULT_ENTITY_KEY,
338
311
  };
312
+
313
+ if ( window.__experimentalEnableSync ) {
314
+ if ( globalThis.IS_GUTENBERG_PLUGIN ) {
315
+ /**
316
+ * @type {import('@wordpress/sync').SyncConfig}
317
+ */
318
+ entity.syncConfig = {
319
+ /**
320
+ * Apply changes from the local editor to the local CRDT document so
321
+ * that those changes can be synced to other peers (via the provider).
322
+ *
323
+ * @param {import('@wordpress/sync').CRDTDoc} crdtDoc
324
+ * @param {Partial< import('@wordpress/sync').ObjectData >} changes
325
+ * @return {void}
326
+ */
327
+ applyChangesToCRDTDoc: ( crdtDoc, changes ) =>
328
+ applyPostChangesToCRDTDoc( crdtDoc, changes, postType ),
329
+
330
+ /**
331
+ * Extract changes from a CRDT document that can be used to update the
332
+ * local editor state.
333
+ *
334
+ * @param {import('@wordpress/sync').CRDTDoc} crdtDoc
335
+ * @param {import('@wordpress/sync').ObjectData} editedRecord
336
+ * @return {Partial< import('@wordpress/sync').ObjectData >} Changes to record
337
+ */
338
+ getChangesFromCRDTDoc: ( crdtDoc, editedRecord ) =>
339
+ getPostChangesFromCRDTDoc(
340
+ crdtDoc,
341
+ editedRecord,
342
+ postType
343
+ ),
344
+
345
+ /**
346
+ * Sync features supported by the entity.
347
+ *
348
+ * @type {Record< string, boolean >}
349
+ */
350
+ supports: {},
351
+ };
352
+ }
353
+ }
354
+
355
+ return entity;
339
356
  } );
340
357
  }
341
358
 
@@ -372,14 +389,23 @@ async function loadSiteEntity() {
372
389
  label: __( 'Site' ),
373
390
  name: 'site',
374
391
  kind: 'root',
392
+ key: false,
375
393
  baseURL: '/wp/v2/settings',
376
- syncConfig: {
377
- applyChangesToCRDTDoc: defaultApplyChangesToCRDTDoc,
378
- getChangesFromCRDTDoc: defaultGetChangesFromCRDTDoc,
379
- },
380
394
  meta: {},
381
395
  };
382
396
 
397
+ if ( window.__experimentalEnableSync ) {
398
+ if ( globalThis.IS_GUTENBERG_PLUGIN ) {
399
+ /**
400
+ * @type {import('@wordpress/sync').SyncConfig}
401
+ */
402
+ entity.syncConfig = {
403
+ applyChangesToCRDTDoc: defaultApplyChangesToCRDTDoc,
404
+ getChangesFromCRDTDoc: defaultGetChangesFromCRDTDoc,
405
+ };
406
+ }
407
+ }
408
+
383
409
  const site = await apiFetch( {
384
410
  path: entity.baseURL,
385
411
  method: 'OPTIONS',
@@ -240,38 +240,13 @@ export const getTemplateId = createRegistrySelector(
240
240
  // First see if the post/page has an assigned template and fetch it.
241
241
  const currentTemplateSlug = editedEntity.template;
242
242
  if ( currentTemplateSlug ) {
243
- const userTemplates = select( STORE_NAME ).getEntityRecords(
244
- 'postType',
245
- 'wp_template',
246
- { per_page: -1 }
247
- );
248
- if ( ! userTemplates ) {
249
- return;
250
- }
251
- const userTemplateWithSlug = userTemplates.find(
252
- ( { slug } ) => slug === currentTemplateSlug
253
- );
254
-
255
- if ( userTemplateWithSlug ) {
256
- return userTemplateWithSlug.id;
257
- }
258
-
259
- const registeredTemplates = select( STORE_NAME ).getEntityRecords(
260
- 'postType',
261
- 'wp_registered_template',
262
- { per_page: -1 }
263
- );
264
-
265
- if ( ! registeredTemplates ) {
266
- return;
267
- }
268
-
269
- const registeredTemplateWithSlug = registeredTemplates.find(
270
- ( { slug } ) => slug === currentTemplateSlug
271
- );
272
-
273
- if ( registeredTemplateWithSlug ) {
274
- return registeredTemplateWithSlug.id;
243
+ const currentTemplate = select( STORE_NAME )
244
+ .getEntityRecords( 'postType', 'wp_template', {
245
+ per_page: -1,
246
+ } )
247
+ ?.find( ( { slug } ) => slug === currentTemplateSlug );
248
+ if ( currentTemplate ) {
249
+ return currentTemplate.id;
275
250
  }
276
251
  }
277
252
  // If no template is assigned, use the default template.
package/src/resolvers.js CHANGED
@@ -15,7 +15,7 @@ import apiFetch from '@wordpress/api-fetch';
15
15
  */
16
16
  import { STORE_NAME } from './name';
17
17
  import { additionalEntityConfigLoaders, DEFAULT_ENTITY_KEY } from './entities';
18
- import { syncManager } from './sync';
18
+ import { getSyncManager } from './sync';
19
19
  import {
20
20
  forwardResolver,
21
21
  getNormalizedCommaSeparable,
@@ -185,7 +185,7 @@ export const getEntityRecord =
185
185
  } );
186
186
 
187
187
  // Load the entity record for syncing.
188
- await syncManager.load(
188
+ await getSyncManager()?.load(
189
189
  entityConfig.syncConfig,
190
190
  objectType,
191
191
  objectId,
@@ -329,7 +329,7 @@ export const getEntityRecords =
329
329
  // the registered templates and rewrites IDs in the form of
330
330
  // `theme-slug/template-slug`. When turned off, we only fetch
331
331
  // database templates (posts). To fetch registered templates without
332
- // edits applied, use the `wp_registered_template` entity.
332
+ // edits applied, use the `registeredTemplate` entity.
333
333
  const { combinedTemplates = true } = query;
334
334
 
335
335
  if (
@@ -899,10 +899,6 @@ export const getDefaultTemplateId =
899
899
  // Endpoint may return an empty object if no template is found.
900
900
  if ( id ) {
901
901
  template.id = id;
902
- template.type =
903
- typeof id === 'string'
904
- ? 'wp_registered_template'
905
- : 'wp_template';
906
902
  registry.batch( () => {
907
903
  dispatch.receiveDefaultTemplateId( query, id );
908
904
  dispatch.receiveEntityRecords( 'postType', template.type, [
package/src/sync.ts CHANGED
@@ -5,8 +5,20 @@ import {
5
5
  CRDT_RECORD_MAP_KEY,
6
6
  LOCAL_EDITOR_ORIGIN,
7
7
  LOCAL_SYNC_MANAGER_ORIGIN,
8
+ type SyncManager,
8
9
  createSyncManager,
9
10
  } from '@wordpress/sync';
10
11
 
11
12
  export { CRDT_RECORD_MAP_KEY, LOCAL_EDITOR_ORIGIN, LOCAL_SYNC_MANAGER_ORIGIN };
12
- export const syncManager = createSyncManager();
13
+
14
+ let syncManager: SyncManager;
15
+
16
+ export function getSyncManager(): SyncManager | undefined {
17
+ if ( syncManager ) {
18
+ return syncManager;
19
+ }
20
+
21
+ syncManager = createSyncManager();
22
+
23
+ return syncManager;
24
+ }
@@ -6,13 +6,11 @@ import triggerFetch from '@wordpress/api-fetch';
6
6
  /**
7
7
  * Internal dependencies
8
8
  */
9
- import { syncManager } from '../sync';
9
+ import { getSyncManager } from '../sync';
10
10
 
11
11
  jest.mock( '@wordpress/api-fetch' );
12
12
  jest.mock( '../sync', () => ( {
13
- syncManager: {
14
- load: jest.fn(),
15
- },
13
+ getSyncManager: jest.fn(),
16
14
  } ) );
17
15
 
18
16
  /**
@@ -42,6 +40,8 @@ describe( 'getEntityRecord', () => {
42
40
  const resolveSelect = { getEntitiesConfig: jest.fn( () => ENTITIES ) };
43
41
 
44
42
  let dispatch;
43
+ let syncManager;
44
+
45
45
  beforeEach( async () => {
46
46
  dispatch = Object.assign( jest.fn(), {
47
47
  receiveEntityRecords: jest.fn(),
@@ -51,7 +51,11 @@ describe( 'getEntityRecord', () => {
51
51
  finishResolutions: jest.fn(),
52
52
  } );
53
53
  triggerFetch.mockReset();
54
- syncManager.load.mockClear();
54
+
55
+ syncManager = {
56
+ load: jest.fn(),
57
+ };
58
+ getSyncManager.mockImplementation( () => syncManager );
55
59
  } );
56
60
 
57
61
  afterEach( () => {