Skip to content
Closed
Changes from 1 commit
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
19 changes: 19 additions & 0 deletions packages/core-data/src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,25 @@ export const saveEntityRecord =
'wp_registered_template',
recordId
);
// Evaluate optimized edits.
// (Function edits that should be evaluated on save to avoid expensive computations on every edit.)
for ( const [ key, value ] of Object.entries( record ) ) {
if ( typeof value === 'function' ) {
const evaluatedValue = value(
select.getEditedEntityRecord( kind, name, recordId )
Copy link
Member Author

Choose a reason for hiding this comment

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

Honestly not sure why this works because this is basically:

wp.data.select('core').getEditedEntityRecord('postType','wp_template','twentytwentyfour//home');

And there should be no edited entities with those IDs 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Haven't checked, but it might be resolver forwarding. It looks like getEntityRecord is backward compatible.

/**
* Requests an entity's record from the REST API.
*/
export const getEditedEntityRecord = forwardResolver( 'getEntityRecord' );

Copy link
Member Author

Choose a reason for hiding this comment

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

Omg, you're right!

Copy link
Member

Choose a reason for hiding this comment

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

Discovered a related (forwarded resolver) but different issue with this action recently as well 😅

#71927 (comment)

);
dispatch.editEntityRecord(
kind,
name,
recordId,
{
[ key ]: evaluatedValue,
},
{ undoIgnore: true }
);
record[ key ] = evaluatedValue;
}
}
// Duplicate the theme template and make the edit.
const newTemplate = await dispatch.saveEntityRecord(
'postType',
Expand Down
Loading