From d88aa4d74fd884a596989a2a25ba4bec1f35c5f8 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 28 Jun 2023 15:55:23 +0100 Subject: [PATCH] =?UTF-8?q?Only=20flush=20the=20`getEntityRecords`=20cache?= =?UTF-8?q?=20if=20the=20fallback=20isn=E2=80=99t=20already=20in=20state?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core-data/src/resolvers.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/core-data/src/resolvers.js b/packages/core-data/src/resolvers.js index 32baa691ddd82..bc4dfda7a6c0d 100644 --- a/packages/core-data/src/resolvers.js +++ b/packages/core-data/src/resolvers.js @@ -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, @@ -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',