WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.53k stars 4.21k forks source link

`saveEditedEntityRecord` does not always save the entity record #67161

Open mikachan opened 2 days ago

mikachan commented 2 days ago

Description

saveEditedEntityRecord does not always save the entity record, meaning that both saveEditedEntityRecord and saveEntityRecord need to be called in order to save an entity record successfully.

Taking a quick look at the saveEditedEntityRecord function, it does call saveEntityRecord, but there are some cases where I believe it's returning early unnecessarily, meaning saveEntityRecord needs to be specifically called. I think it's when recordId is undefined, which it will be if saving global site settings which do not require an ID.

This came up while working on https://github.com/WordPress/gutenberg/pull/65426/#discussion_r1850029321.

Step-by-step reproduction instructions

Try saving the global site settings via saveEditedEntityRecord:

saveEditedEntityRecord( 'root', 'site', undefined, {
    page_on_front: item.id,
    show_on_front: 'page',
} );

The site settings will not be saved. However, if you run saveEntityRecord immediately before it, the site settings will be saved successfully:

saveEntityRecord( 'root', 'site', {
    page_on_front: [page id],
    show_on_front: 'page',
} );

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Please confirm which theme type you used for testing.