Skip to content

Commit

Permalink
Editor: Fix block context defined for template parts (#58807)
Browse files Browse the repository at this point in the history
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: gziolo <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: annezazu <[email protected]>
Co-authored-by: colorful-tones <[email protected]>
  • Loading branch information
6 people authored Feb 8, 2024
1 parent ca4c232 commit 3f8a858
Showing 1 changed file with 15 additions and 2 deletions.
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 = [
'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

1 comment on commit 3f8a858

@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 3f8a858.
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/7828487572
📝 Reported issues:

Please sign in to comment.