Skip to content

Commit

Permalink
Fix fetching Nav fallback ID flushing Navigation entity cache (#52069)
Browse files Browse the repository at this point in the history
* Only flush the `getEntityRecords` cache if the fallback isn’t already in state

* Save the edited entity record to a const and then invert it to determine whether we should invalidate the recordds

---------

Co-authored-by: scruffian <[email protected]>
  • Loading branch information
getdave and scruffian authored Jun 29, 2023
1 parent 55c18fc commit 3633d94
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/core-data/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ export const getBlockPatternCategories =

export const getNavigationFallbackId =
() =>
async ( { dispatch } ) => {
async ( { dispatch, select } ) => {
const fallback = await apiFetch( {
path: addQueryArgs( '/wp-block-editor/v1/navigation-fallback', {
_embed: true,
Expand All @@ -585,8 +585,15 @@ export const getNavigationFallbackId =
dispatch.receiveNavigationFallbackId( fallback?.id );

if ( record ) {
const invalidateNavigationQueries = true;

// 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',
Expand Down

0 comments on commit 3633d94

Please sign in to comment.