Skip to content

Commit

Permalink
Core Data: Check post-type support before requesting autosaves (WordP…
Browse files Browse the repository at this point in the history
…ress#68680)


Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: swissspidy <swissspidy@git.wordpress.org>
  • Loading branch information
3 people authored Jan 15, 2025
1 parent 5a5455c commit 23e0db4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
11 changes: 9 additions & 2 deletions packages/core-data/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,15 @@ export const canUserEditEntityRecord =
export const getAutosaves =
( postType, postId ) =>
async ( { dispatch, resolveSelect } ) => {
const { rest_base: restBase, rest_namespace: restNamespace = 'wp/v2' } =
await resolveSelect.getPostType( postType );
const {
rest_base: restBase,
rest_namespace: restNamespace = 'wp/v2',
supports,
} = await resolveSelect.getPostType( postType );
if ( ! supports?.autosave ) {
return;
}

const autosaves = await apiFetch( {
path: `/${ restNamespace }/${ restBase }/${ postId }/autosaves?context=edit`,
} );
Expand Down
10 changes: 8 additions & 2 deletions packages/core-data/src/test/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,10 @@ describe( 'getAutosaves', () => {
const postType = 'post';
const postId = 1;
const restBase = 'posts';
const postEntityConfig = { rest_base: restBase };
const postEntityConfig = {
rest_base: restBase,
supports: { autosave: true },
};

triggerFetch.mockImplementation( () => SUCCESSFUL_RESPONSE );
const dispatch = Object.assign( jest.fn(), {
Expand All @@ -750,7 +753,10 @@ describe( 'getAutosaves', () => {
const postType = 'post';
const postId = 1;
const restBase = 'posts';
const postEntityConfig = { rest_base: restBase };
const postEntityConfig = {
rest_base: restBase,
supports: { autosave: true },
};

triggerFetch.mockImplementation( () => [] );
const dispatch = Object.assign( jest.fn(), {
Expand Down

0 comments on commit 23e0db4

Please sign in to comment.