Skip to content

Commit 1352cf5

Browse files
committed
Core Data: Avoid extraneous when creating a new record
1 parent efb328b commit 1352cf5

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

packages/core-data/src/actions.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,9 @@ export const saveEntityRecord =
525525
if ( ! entityConfig ) {
526526
return;
527527
}
528-
const entityIdKey = entityConfig.key || DEFAULT_ENTITY_KEY;
528+
const entityIdKey = entityConfig.key ?? DEFAULT_ENTITY_KEY;
529529
const recordId = record[ entityIdKey ];
530+
const isNewRecord = !! entityIdKey && ! recordId;
530531

531532
const lock = await dispatch.__unstableAcquireStoreLock(
532533
STORE_NAME,
@@ -580,11 +581,10 @@ export const saveEntityRecord =
580581
}
581582
try {
582583
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+
: {};
588588

589589
if ( isAutosave ) {
590590
// Most of this autosave logic is very specific to posts.

packages/core-data/src/entities.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export const rootEntitiesConfig = [
3636
{
3737
label: __( 'Base' ),
3838
kind: 'root',
39+
key: false,
3940
name: '__unstableBase',
4041
baseURL: '/',
4142
baseURLParams: {
@@ -381,6 +382,7 @@ async function loadSiteEntity() {
381382
label: __( 'Site' ),
382383
name: 'site',
383384
kind: 'root',
385+
key: false,
384386
baseURL: '/wp/v2/settings',
385387
meta: {},
386388
};

0 commit comments

Comments
 (0)