Skip to content

Commit

Permalink
Navigation: Avoid using embedded records from fallback API (#59076)
Browse files Browse the repository at this point in the history
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
  • Loading branch information
3 people committed Feb 20, 2024
1 parent 4cebe35 commit a7dbaa7
Showing 1 changed file with 2 additions and 32 deletions.
34 changes: 2 additions & 32 deletions packages/core-data/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -661,42 +661,12 @@ export const getUserPatternCategories =

export const getNavigationFallbackId =
() =>
async ( { dispatch, select } ) => {
async ( { dispatch } ) => {
const fallback = await apiFetch( {
path: addQueryArgs( '/wp-block-editor/v1/navigation-fallback', {
_embed: true,
} ),
path: addQueryArgs( '/wp-block-editor/v1/navigation-fallback' ),
} );

const record = fallback?._embedded?.self;

dispatch.receiveNavigationFallbackId( fallback?.id );

if ( record ) {
// If the fallback is already in the store, don't invalidate navigation queries.
// Otherwise, invalidate the cache for the scenario where there were no Navigation
// posts in the state and the fallback created one.
const existingFallbackEntityRecord = select.getEntityRecord(
'postType',
'wp_navigation',
fallback?.id
);
const invalidateNavigationQueries = ! existingFallbackEntityRecord;
dispatch.receiveEntityRecords(
'postType',
'wp_navigation',
record,
undefined,
invalidateNavigationQueries
);

// Resolve to avoid further network requests.
dispatch.finishResolution( 'getEntityRecord', [
'postType',
'wp_navigation',
fallback?.id,
] );
}
};

export const getDefaultTemplateId =
Expand Down

0 comments on commit a7dbaa7

Please sign in to comment.