Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: Fix block context defined for template parts #58807

Merged
merged 2 commits into from
Feb 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions packages/editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ const { ExperimentalBlockEditorProvider } = unlock( blockEditorPrivateApis );
const { PatternsMenuItems } = unlock( editPatternsPrivateApis );

const noop = () => {};
const NON_CONTEXTUAL_POST_TYPES = [
Copy link
Member

Choose a reason for hiding this comment

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

Would be helpful to explain further what these are or why they are distinct

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Follow-up here #58836

'wp_block',
'wp_template',
'wp_navigation',
'wp_template_part',
];

/**
* Depending on the post, template and template mode,
Expand Down Expand Up @@ -113,7 +119,8 @@ export const ExperimentalEditorProvider = withRegistryProvider(
const rootLevelPost = shouldRenderTemplate ? template : post;
const defaultBlockContext = useMemo( () => {
const postContext =
rootLevelPost.type !== 'wp_template' || shouldRenderTemplate
! NON_CONTEXTUAL_POST_TYPES.includes( rootLevelPost.type ) ||
shouldRenderTemplate
? { postId: post.id, postType: post.type }
: {};

Expand All @@ -124,7 +131,13 @@ export const ExperimentalEditorProvider = withRegistryProvider(
? rootLevelPost.slug
: undefined,
};
}, [ post.id, post.type, rootLevelPost.type, rootLevelPost.slug ] );
}, [
shouldRenderTemplate,
post.id,
post.type,
rootLevelPost.type,
rootLevelPost.slug,
] );
const { editorSettings, selection, isReady } = useSelect(
( select ) => {
const {
Expand Down
Loading