Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 6 additions & 6 deletions packages/core-data/src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,9 @@ export const saveEntityRecord =
if ( ! entityConfig ) {
return;
}
const entityIdKey = entityConfig.key || DEFAULT_ENTITY_KEY;
const entityIdKey = entityConfig.key ?? DEFAULT_ENTITY_KEY;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think it makes sense to update similar assignments to use the nullish coalescing operator. The entity either has a key defined or will be using the fallback.

I don't expect this to be a breaking change.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@youknowriad, what do you think about this? Should I make similar changes in other places? Mostly for consistency.

const recordId = record[ entityIdKey ];
const isNewRecord = !! entityIdKey && ! recordId;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are we concerned about entityIdKey here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

For the root/site, it will be intentionally false - #72666 (comment). It's more like a safeguard.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's a smallish breaking change I guess but I don't really expect impact, WDYT.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't expect this to break any consumer code.


const lock = await dispatch.__unstableAcquireStoreLock(
STORE_NAME,
Expand Down Expand Up @@ -580,11 +581,10 @@ export const saveEntityRecord =
}
try {
const path = `${ baseURL }${ recordId ? '/' + recordId : '' }`;
const persistedRecord = select.getRawEntityRecord(
kind,
name,
recordId
);
// Skip the raw values check when creating a new record; they don't exist yet.
const persistedRecord = ! isNewRecord
? select.getRawEntityRecord( kind, name, recordId )
: {};

if ( isAutosave ) {
// Most of this autosave logic is very specific to posts.
Expand Down
2 changes: 2 additions & 0 deletions packages/core-data/src/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const rootEntitiesConfig = [
{
label: __( 'Base' ),
kind: 'root',
key: false,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The root/base is ready only, but adding this here just in case. Should I include an inline comment on why the key is intentionally false?

name: '__unstableBase',
baseURL: '/',
baseURLParams: {
Expand Down Expand Up @@ -381,6 +382,7 @@ async function loadSiteEntity() {
label: __( 'Site' ),
name: 'site',
kind: 'root',
key: false,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Same here, should I add a comment?

baseURL: '/wp/v2/settings',
meta: {},
};
Expand Down
Loading