Skip to content

Commit

Permalink
invalidate default template
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Nov 14, 2024
1 parent db59bdb commit f36477c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/core-data/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ export const getCurrentUser =
export const getEntityRecord =
( kind, name, key = '', query ) =>
async ( { select, dispatch, registry, resolveSelect } ) => {
// For back-compat, we allow querying for static templates through
// wp_template.
if (
kind === 'postType' &&
name === 'wp_template' &&
typeof key === 'string'
) {
name = '_wp_static_template';
}
const configs = await resolveSelect.getEntitiesConfig( kind );
const entityConfig = configs.find(
( config ) => config.name === name && config.kind === kind
Expand Down Expand Up @@ -820,6 +829,15 @@ export const getDefaultTemplateId =
}
};

// Whenever the active template is changed, we must lookup again.
getDefaultTemplateId.shouldInvalidate = ( action ) => {
return (
action.type === 'RECEIVE_ITEMS' &&
action.kind === 'postType' &&
action.name === 'wp_template'
);
};

/**
* Requests an entity's revisions from the REST API.
*
Expand Down
9 changes: 9 additions & 0 deletions packages/core-data/src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,15 @@ export const getEntityRecord = createSelector(
key: EntityRecordKey,
query?: GetRecordsHttpQuery
): EntityRecord | undefined => {
// For back-compat, we allow querying for static templates through
// wp_template.
if (
kind === 'postType' &&
name === 'wp_template' &&
typeof key === 'string'
) {
name = '_wp_static_template';
}
const queriedState =
state.entities.records?.[ kind ]?.[ name ]?.queriedData;
if ( ! queriedState ) {
Expand Down

0 comments on commit f36477c

Please sign in to comment.