Skip to content

Commit

Permalink
Fix retrieving autosaves when using a custom rest_namespace (#41542)
Browse files Browse the repository at this point in the history
* Fix retrieving autosaves when using a custom rest_namespace

When specifying `rest_namespace` in a custom post type, a hardcoded `wp/v2` in `getAutosaves` results in a 404

* linter fixes for rest namespace resolution in autosave resolver

* try to fix autosave resolver and namespaces not present

* update resolvers for autosaves endpoint

* Fix prettier erro

Co-authored-by: Jonny Harris <[email protected]>

Co-authored-by: Jonny Harris <[email protected]>
Co-authored-by: George Mamadashvili <[email protected]>
  • Loading branch information
3 people authored Jun 27, 2022
1 parent 213bd58 commit d81b923
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions packages/core-data/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,10 @@ export const canUserEditEntityRecord =
export const getAutosaves =
( postType, postId ) =>
async ( { dispatch, resolveSelect } ) => {
const { rest_base: restBase } = await resolveSelect.getPostType(
postType
);
const { rest_base: restBase, rest_namespace: restNamespace = 'wp/v2' } =
await resolveSelect.getPostType( postType );
const autosaves = await apiFetch( {
path: `/wp/v2/${ restBase }/${ postId }/autosaves?context=edit`,
path: `/${ restNamespace }/${ restBase }/${ postId }/autosaves?context=edit`,
} );

if ( autosaves && autosaves.length ) {
Expand Down

0 comments on commit d81b923

Please sign in to comment.