File tree Expand file tree Collapse file tree 2 files changed +17
–2
lines changed
Expand file tree Collapse file tree 2 files changed +17
–2
lines changed Original file line number Diff line number Diff line change @@ -495,6 +495,14 @@ describe( 'isUnmodifiedBlock', () => {
495495 expect ( isUnmodifiedBlock ( block , 'non-existent-role' ) ) . toBe ( true ) ;
496496 } ) ;
497497
498+ it ( 'should return false if no attributes exist for the role and some are modified' , ( ) => {
499+ const block = createBlock ( 'core/test-block' , {
500+ align : 'center' ,
501+ content : 'Updated content' ,
502+ } ) ;
503+ expect ( isUnmodifiedBlock ( block , 'non-existent-role' ) ) . toBe ( false ) ;
504+ } ) ;
505+
498506 it ( 'should return true if metadata attributes is not modified for role content' , ( ) => {
499507 const block = createBlock ( 'core/test-block' ) ;
500508 expect ( isUnmodifiedBlock ( block , 'content' ) ) . toBe ( true ) ;
Original file line number Diff line number Diff line change @@ -43,20 +43,27 @@ export function isUnmodifiedBlock( block, role ) {
4343 const blockAttributes = getBlockType ( block . name ) ?. attributes ?? { } ;
4444
4545 // Filter attributes by role if a role is provided.
46- const attributesToCheck = role
46+ const attributesByRole = role
4747 ? Object . entries ( blockAttributes ) . filter ( ( [ key , definition ] ) => {
4848 // A special case for the metadata attribute.
4949 // It can include block bindings that serve as a source of content,
5050 // without directly modifying content attributes.
5151 if ( role === 'content' && key === 'metadata' ) {
52- return true ;
52+ return (
53+ Object . keys ( block . attributes [ key ] ?. bindings ?? { } )
54+ . length > 0
55+ ) ;
5356 }
5457
5558 return (
5659 definition . role === role ||
5760 definition . __experimentalRole === role
5861 ) ;
5962 } )
63+ : [ ] ;
64+ // Fallback to all attributes if no attributes match the role.
65+ const attributesToCheck = ! ! attributesByRole . length
66+ ? attributesByRole
6067 : Object . entries ( blockAttributes ) ;
6168
6269 return attributesToCheck . every ( ( [ key , definition ] ) => {
You can’t perform that action at this time.
0 commit comments