Skip to content
Open
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
3 changes: 2 additions & 1 deletion docs/reference-guides/data/data-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -953,8 +953,9 @@ _Parameters_
- _record_ `Object`: Record to be saved.
- _options_ `Object`: Saving options.
- _options.isAutosave_ `[boolean]`: Whether this is an autosave.
- _options.\_\_unstableFetch_ `[Function]`: Internal use only. Function to call instead of `apiFetch()`. Must return a promise.
- _options.invalidateCache_ `[boolean]`: Whether to invalidate the query caches for the entity once the record is received.
- _options.throwOnError_ `[boolean]`: If false, this action suppresses all the exceptions. Defaults to false.
- _options.\_\_unstableFetch_ `[Function]`: Internal use only. Function to call instead of `apiFetch()`. Must return a promise.

### undo

Expand Down
1 change: 1 addition & 0 deletions packages/core-data/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Enhancements

- Improve error reporting in private action `saveDirtyEntities` ([#81151](https://github.com/WordPress/gutenberg/pull/81151)).
- `saveEntityRecord`: Add an `invalidateCache` option (defaults to `true`) to let consumers opt out of query cache invalidation.

### Bug Fixes

Expand Down
3 changes: 2 additions & 1 deletion packages/core-data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,9 @@ _Parameters_
- _record_ `Object`: Record to be saved.
- _options_ `Object`: Saving options.
- _options.isAutosave_ `[boolean]`: Whether this is an autosave.
- _options.\_\_unstableFetch_ `[Function]`: Internal use only. Function to call instead of `apiFetch()`. Must return a promise.
- _options.invalidateCache_ `[boolean]`: Whether to invalidate the query caches for the entity once the record is received.
- _options.throwOnError_ `[boolean]`: If false, this action suppresses all the exceptions. Defaults to false.
- _options.\_\_unstableFetch_ `[Function]`: Internal use only. Function to call instead of `apiFetch()`. Must return a promise.

### undo

Expand Down
29 changes: 16 additions & 13 deletions packages/core-data/src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,25 +639,28 @@ export const __unstableCreateUndoLevel =
/**
* Action triggered to save an entity record.
*
* @param {string} kind Kind of the received entity.
* @param {string} name Name of the received entity.
* @param {Object} record Record to be saved.
* @param {Object} options Saving options.
* @param {boolean} [options.isAutosave=false] Whether this is an autosave.
* @param {Function} [options.__unstableFetch] Internal use only. Function to
* call instead of `apiFetch()`.
* Must return a promise.
* @param {boolean} [options.throwOnError=false] If false, this action suppresses all
* the exceptions. Defaults to false.
* @param {string} kind Kind of the received entity.
* @param {string} name Name of the received entity.
* @param {Object} record Record to be saved.
* @param {Object} options Saving options.
* @param {boolean} [options.isAutosave=false] Whether this is an autosave.
* @param {boolean} [options.invalidateCache=true] Whether to invalidate the query caches
* for the entity once the record is received.
* @param {boolean} [options.throwOnError=false] If false, this action suppresses all
* the exceptions. Defaults to false.
* @param {Function} [options.__unstableFetch] Internal use only. Function to
* call instead of `apiFetch()`.
* Must return a promise.
*/
export const saveEntityRecord =
( kind, name, record, options = {} ) =>
async ( { select, resolveSelect, dispatch } ) => {
const {
isAutosave = false,
invalidateCache = true,
throwOnError = false,
__unstableFetch = apiFetch,
__unstableSkipSyncUpdate = false,
throwOnError = false,
} = options;

logEntityDeprecation( kind, name, 'saveEntityRecord' );
Expand Down Expand Up @@ -846,7 +849,7 @@ export const saveEntityRecord =
name,
newRecord,
undefined,
true
invalidateCache
);
} else {
dispatch.receiveAutosaves(
Expand Down Expand Up @@ -875,7 +878,7 @@ export const saveEntityRecord =
name,
updatedRecord,
undefined,
true,
invalidateCache,
edits
);
if ( entityConfig.syncConfig ) {
Expand Down
Loading