Skip to content

Commit

Permalink
Only flush the getEntityRecords cache if the fallback isn’t already…
Browse files Browse the repository at this point in the history
… in state
  • Loading branch information
getdave committed Jun 28, 2023
1 parent 2ecd216 commit d88aa4d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 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,7 +585,16 @@ 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 invalidateNavigationQueries = select.getEntityRecord(
'postType',
'wp_navigation',
fallback?.id
)
? false
: true;

dispatch.receiveEntityRecords(
'postType',
Expand Down

0 comments on commit d88aa4d

Please sign in to comment.