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

Template Part Block: Update block isActive method #45672

Merged
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
4 changes: 4 additions & 0 deletions packages/block-library/src/template-part/variations.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export function enhanceTemplatePartVariations( settings, name ) {
'wp_template_part',
`${ theme }//${ slug }`
);

if ( entity?.slug ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we remove optional chaining if ( entity.slug ), I think if is enough, how do you think?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not 100% sure about this, but I think it's pretty safe since getEntityRecord() might not return an object at first., but null.

See: https://developer.wordpress.org/block-editor/reference-guides/data/data-core/#getentityrecord

return entity.slug === variationAttributes.slug;
}
return entity?.area === variationAttributes.area;
};

Expand Down