Skip to content

saveEditedEntityRecord does not always save the entity record #67161

@mikachan

Description

@mikachan

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 #65426.

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 after 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.

  • Yes

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

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Package] Core data/packages/core-data[Type] BugAn existing feature does not function as intended

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions