-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Don't render undefined classname in useBlockProps hook #56923
Conversation
Size Change: +2 B (0%) Total Size: 1.71 MB
ℹ️ View Unchanged
|
Flaky tests detected in 19de0f9. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7157651594
|
@@ -191,7 +191,8 @@ export function useBlockProps( props = {}, { __unstableIsHtml } = {} ) { | |||
getBlockName( movingClientId ), | |||
getBlockRootClientId( clientId ) | |||
), | |||
[ attributes.className ]: hasLightBlockWrapper, | |||
[ attributes.className ]: | |||
attributes.className && hasLightBlockWrapper, | |||
[ getBlockDefaultClassName( blockName ) ]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this also be undefined or null? Maybe we shouldn't add either one through an object, and add hasLightBlockWrapper ? attributes.className : undefined
after it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this also be undefined or null?
This can happen. This is because the blocks.getBlockDefaultClassName
hook allows consumers to intentionally return undefined
.
wp.hooks.addFilter(
'blocks.getBlockDefaultClassName',
'my-plugin/remove-block-class-name',
function( className, blockName ) {
return undefined;
}
);
I've updated the PR to take this case into account as well.
Related to #56847
What?
This PR removes
undefined
class that is rendered when a block has no additional CSS classes.Why?
We need to check that
attributes.className
does not appear undefined. This existed before #56847 refactored the useBlockProps hook.Testing Instructions