Skip to content

Commit

Permalink
Revert removal of Nav fallback auto embed (#59220)
Browse files Browse the repository at this point in the history
*  Revert the changes that removed the feature

* Fix nits


Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: MaggieCabrera <onemaggie@git.wordpress.org>
Co-authored-by: kevin940726 <kevin940726@git.wordpress.org>
  • Loading branch information
4 people committed Feb 27, 2024
1 parent 57030d3 commit 5d4028f
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions packages/core-data/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -661,12 +661,42 @@ export const getUserPatternCategories =

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

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 5d4028f

Please sign in to comment.