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 authored Feb 16, 2024
1 parent a72d32c commit 7cf8de9
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

1 comment on commit 7cf8de9

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 7cf8de9.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7926002277
📝 Reported issues:

Please sign in to comment.